Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
b0630b81
Commit
b0630b81
authored
Aug 22, 2015
by
woogerboy21
Browse files
Log old session out of server if logging in from a second location
parent
0c0413f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/window_main.cpp
View file @
b0630b81
...
...
@@ -85,6 +85,7 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even
}
case
Event_ConnectionClosed
::
SERVER_SHUTDOWN
:
reasonStr
=
tr
(
"Scheduled server shutdown."
);
break
;
case
Event_ConnectionClosed
::
USERNAMEINVALID
:
reasonStr
=
tr
(
"Invalid username."
);
break
;
case
Event_ConnectionClosed
::
LOGGEDINELSEWERE
:
reasonStr
=
tr
(
"You have been logged out due to logging in at another location."
);
break
;
default:
reasonStr
=
QString
::
fromStdString
(
event
.
reason_str
());
}
QMessageBox
::
critical
(
this
,
tr
(
"Connection closed"
),
tr
(
"The server has terminated your connection.
\n
Reason: %1"
).
arg
(
reasonStr
));
...
...
common/pb/event_connection_closed.proto
View file @
b0630b81
...
...
@@ -12,6 +12,7 @@ message Event_ConnectionClosed {
USERNAMEINVALID
=
5
;
USER_LIMIT_REACHED
=
6
;
DEMOTED
=
7
;
LOGGEDINELSEWERE
=
8
;
}
optional
CloseReason
reason
=
1
;
optional
string
reason_str
=
2
;
...
...
common/server.cpp
View file @
b0630b81
...
...
@@ -30,6 +30,7 @@
#include
"pb/event_user_left.pb.h"
#include
"pb/event_list_rooms.pb.h"
#include
"pb/session_event.pb.h"
#include
"pb/event_connection_closed.pb.h"
#include
"pb/isl_message.pb.h"
#include
<QCoreApplication>
#include
<QThread>
...
...
@@ -126,9 +127,17 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
// verify that new session would not cause problems with older existing session
if
(
users
.
contains
(
name
)
||
databaseInterface
->
userSessionExists
(
name
))
{
qDebug
(
"Login denied: would overwrite old session"
);
databaseInterface
->
unlockSessionTables
();
return
WouldOverwriteOldSession
;
qDebug
(
"Session already logged in, logging old session out"
);
Event_ConnectionClosed
event
;
event
.
set_reason
(
Event_ConnectionClosed
::
LOGGEDINELSEWERE
);
event
.
set_reason_str
(
"You have been logged out due to logging in at another location."
);
event
.
set_end_time
(
QDateTime
::
currentDateTime
().
toTime_t
());
SessionEvent
*
se
=
users
.
value
(
name
)
->
prepareSessionEvent
(
event
);
users
.
value
(
name
)
->
sendProtocolItem
(
*
se
);
delete
se
;
}
}
else
if
(
authState
==
UnknownUser
)
{
// Change user name so that no two users have the same names,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment