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
b9087715
Commit
b9087715
authored
May 09, 2012
by
Max-Wilhelm Bruker
Browse files
fixed issue #42: make 'client deprecated' message work for v13 client <-> v14 server
parent
f7975d8a
Changes
7
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/remoteclient.cpp
View file @
b9087715
...
...
@@ -9,10 +9,10 @@
#include
"pb/server_message.pb.h"
#include
"pb/event_server_identification.pb.h"
static
const
unsigned
int
protocolVersion
=
1
3
;
static
const
unsigned
int
protocolVersion
=
1
4
;
RemoteClient
::
RemoteClient
(
QObject
*
parent
)
:
AbstractClient
(
parent
),
timeRunning
(
0
),
lastDataReceived
(
0
),
messageInProgress
(
false
),
messageLength
(
0
)
:
AbstractClient
(
parent
),
timeRunning
(
0
),
lastDataReceived
(
0
),
messageInProgress
(
false
),
handshakeStarted
(
false
),
messageLength
(
0
)
{
timer
=
new
QTimer
(
this
);
timer
->
setInterval
(
1000
);
...
...
@@ -47,6 +47,11 @@ void RemoteClient::slotConnected()
{
timeRunning
=
lastDataReceived
=
0
;
timer
->
start
();
// dirty hack to be compatible with v14 server
sendCommandContainer
(
CommandContainer
());
// end of hack
setStatus
(
StatusAwaitingWelcome
);
}
...
...
@@ -54,7 +59,7 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
{
if
(
event
.
protocol_version
()
!=
protocolVersion
)
{
emit
protocolVersionMismatch
(
protocolVersion
,
event
.
protocol_version
());
setStatus
(
StatusDisconnect
ed
);
setStatus
(
StatusDisconnect
ing
);
return
;
}
setStatus
(
StatusLoggingIn
);
...
...
@@ -105,12 +110,22 @@ void RemoteClient::readData()
do
{
if
(
!
messageInProgress
)
{
if
(
inputBuffer
.
size
()
>=
4
)
{
messageLength
=
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
0
])
<<
24
)
+
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
1
])
<<
16
)
+
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
2
])
<<
8
)
+
((
quint32
)
(
unsigned
char
)
inputBuffer
[
3
]);
inputBuffer
.
remove
(
0
,
4
);
messageInProgress
=
true
;
// dirty hack to be compatible with v14 server that sends 60 bytes of garbage at the beginning
if
(
!
handshakeStarted
)
{
handshakeStarted
=
true
;
if
(
inputBuffer
.
startsWith
(
"<?xm"
))
{
messageInProgress
=
true
;
messageLength
=
60
;
}
}
else
{
// end of hack
messageLength
=
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
0
])
<<
24
)
+
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
1
])
<<
16
)
+
(((
quint32
)
(
unsigned
char
)
inputBuffer
[
2
])
<<
8
)
+
((
quint32
)
(
unsigned
char
)
inputBuffer
[
3
]);
inputBuffer
.
remove
(
0
,
4
);
messageInProgress
=
true
;
}
}
else
return
;
}
...
...
@@ -126,10 +141,10 @@ void RemoteClient::readData()
messageInProgress
=
false
;
processProtocolItem
(
newServerMessage
);
}
while
(
!
inputBuffer
.
isEmpty
());
if
(
getStatus
()
==
StatusDisconnecting
)
// use thread-safe getter
doDisconnectFromServer
();
if
(
getStatus
()
==
StatusDisconnecting
)
// use thread-safe getter
doDisconnectFromServer
();
}
while
(
!
inputBuffer
.
isEmpty
());
}
void
RemoteClient
::
sendCommandContainer
(
const
CommandContainer
&
cont
)
...
...
cockatrice/src/remoteclient.h
View file @
b9087715
...
...
@@ -33,6 +33,7 @@ private:
QByteArray
inputBuffer
;
bool
messageInProgress
;
bool
handshakeStarted
;
int
messageLength
;
QTimer
*
timer
;
...
...
common/.directory
deleted
100644 → 0
View file @
f7975d8a
[Dolphin]
Timestamp=2012,3,4,11,22,24
Version=2
ViewMode=1
common/pb/commands.proto
View file @
b9087715
...
...
@@ -5,7 +5,7 @@ import "moderator_commands.proto";
import
"admin_commands.proto"
;
message
CommandContainer
{
required
uint64
cmd_id
=
1
;
optional
uint64
cmd_id
=
1
;
optional
uint32
game_id
=
10
;
optional
uint32
room_id
=
20
;
...
...
servatrice/src/servatrice.cpp
View file @
b9087715
...
...
@@ -43,10 +43,11 @@ void Servatrice_GameServer::incomingConnection(int socketDescriptor)
sst
->
start
();
}
else
{
QTcpSocket
*
socket
=
new
QTcpSocket
;
ServerSocketInterface
*
ssi
=
new
ServerSocketInterface
(
server
,
socket
);
socket
->
setSocketDescriptor
(
socketDescriptor
);
socket
->
setSocketOption
(
QAbstractSocket
::
LowDelayOption
,
1
);
ServerSocketInterface
*
ssi
=
new
ServerSocketInterface
(
server
,
socket
);
logger
->
logMessage
(
QString
(
"incoming connection: %1"
).
arg
(
socket
->
peerAddress
().
toString
()),
ssi
);
ssi
->
initSessionDeprecated
();
}
}
...
...
servatrice/src/serversocketinterface.cpp
View file @
b9087715
...
...
@@ -57,17 +57,38 @@
#include
<string>
#include
<iostream>
static
const
int
protocolVersion
=
1
3
;
static
const
int
protocolVersion
=
1
4
;
ServerSocketInterface
::
ServerSocketInterface
(
Servatrice
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
)
:
Server_ProtocolHandler
(
_server
,
parent
),
servatrice
(
_server
),
socket
(
_socket
),
messageInProgress
(
false
)
:
Server_ProtocolHandler
(
_server
,
parent
),
servatrice
(
_server
),
socket
(
_socket
),
messageInProgress
(
false
)
,
handshakeStarted
(
false
)
{
bool
success
=
true
;
connect
(
socket
,
SIGNAL
(
readyRead
()),
this
,
SLOT
(
readClient
()));
connect
(
socket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
catchSocketError
(
QAbstractSocket
::
SocketError
)));
connect
(
this
,
SIGNAL
(
outputBufferChanged
()),
this
,
SLOT
(
flushOutputBuffer
()),
Qt
::
QueuedConnection
);
}
ServerSocketInterface
::~
ServerSocketInterface
()
{
logger
->
logMessage
(
"ServerSocketInterface destructor"
,
this
);
flushOutputBuffer
();
delete
socket
;
socket
=
0
;
}
void
ServerSocketInterface
::
initSessionDeprecated
()
{
// dirty hack to make v13 client display the correct error message
outputBufferMutex
.
lock
();
outputBuffer
=
"<?xml version=
\"
1.0
\"
?><cockatrice_server_stream version=
\"
14
\"
>"
;
outputBufferMutex
.
unlock
();
emit
outputBufferChanged
();
}
bool
ServerSocketInterface
::
initSession
()
{
Event_ServerIdentification
identEvent
;
identEvent
.
set_server_name
(
servatrice
->
getServerName
().
toStdString
());
identEvent
.
set_server_version
(
VERSION_STRING
);
...
...
@@ -76,30 +97,19 @@ ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_s
sendProtocolItem
(
*
identSe
);
delete
identSe
;
int
maxUsers
=
_
serve
r
->
getMaxUsersPerAddress
();
if
((
maxUsers
>
0
)
&&
(
_
serve
r
->
getUsersWithAddress
(
socket
->
peerAddress
())
>=
maxUsers
))
{
int
maxUsers
=
serv
atric
e
->
getMaxUsersPerAddress
();
if
((
maxUsers
>
0
)
&&
(
serv
atric
e
->
getUsersWithAddress
(
socket
->
peerAddress
())
>=
maxUsers
))
{
Event_ConnectionClosed
event
;
event
.
set_reason
(
Event_ConnectionClosed
::
TOO_MANY_CONNECTIONS
);
SessionEvent
*
se
=
prepareSessionEvent
(
event
);
sendProtocolItem
(
*
se
);
delete
se
;
success
=
false
;
return
false
;
}
server
->
addClient
(
this
);
if
(
!
success
)
prepareDestroy
();
}
ServerSocketInterface
::~
ServerSocketInterface
()
{
logger
->
logMessage
(
"ServerSocketInterface destructor"
,
this
);
flushOutputBuffer
();
delete
socket
;
socket
=
0
;
return
true
;
}
void
ServerSocketInterface
::
flushOutputBuffer
()
...
...
@@ -139,7 +149,15 @@ void ServerSocketInterface::readClient()
inputBuffer
.
remove
(
0
,
messageLength
);
messageInProgress
=
false
;
processCommandContainer
(
newCommandContainer
);
// dirty hack to make v13 client display the correct error message
if
(
handshakeStarted
)
processCommandContainer
(
newCommandContainer
);
else
if
(
!
newCommandContainer
.
has_cmd_id
())
{
handshakeStarted
=
true
;
if
(
!
initSession
())
prepareDestroy
();
}
// end of hack
}
while
(
!
inputBuffer
.
isEmpty
());
}
...
...
servatrice/src/serversocketinterface.h
View file @
b9087715
...
...
@@ -63,6 +63,7 @@ private:
QByteArray
inputBuffer
,
outputBuffer
;
bool
messageInProgress
;
bool
handshakeStarted
;
int
messageLength
;
Response
::
ResponseCode
cmdAddToList
(
const
Command_AddToList
&
cmd
,
ResponseContainer
&
rc
);
...
...
@@ -92,6 +93,8 @@ private:
public:
ServerSocketInterface
(
Servatrice
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
=
0
);
~
ServerSocketInterface
();
void
initSessionDeprecated
();
bool
initSession
();
QHostAddress
getPeerAddress
()
const
{
return
socket
->
peerAddress
();
}
QString
getAddress
()
const
{
return
socket
->
peerAddress
().
toString
();
}
...
...
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