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
c1b75228
Commit
c1b75228
authored
Nov 17, 2009
by
Max-Wilhelm Bruker
Browse files
blah
parent
7a07a395
Changes
5
Show whitespace changes
Inline
Side-by-side
common/protocol_items.cpp
View file @
c1b75228
...
@@ -21,17 +21,17 @@ Command_DeckList::Command_DeckList()
...
@@ -21,17 +21,17 @@ Command_DeckList::Command_DeckList()
:
Command
(
"deck_list"
)
:
Command
(
"deck_list"
)
{
{
}
}
Command_DeckNewDir
::
Command_DeckNewDir
(
const
QString
&
_path
,
const
QString
&
_
n
ame
)
Command_DeckNewDir
::
Command_DeckNewDir
(
const
QString
&
_path
,
const
QString
&
_
dirN
ame
)
:
Command
(
"deck_new_dir"
),
path
(
_path
),
n
ame
(
_
n
ame
)
:
Command
(
"deck_new_dir"
),
path
(
_path
),
dirN
ame
(
_
dirN
ame
)
{
{
setParameter
(
"path"
,
path
);
setParameter
(
"path"
,
path
);
setParameter
(
"name"
,
n
ame
);
setParameter
(
"
dir_
name"
,
dirN
ame
);
}
}
void
Command_DeckNewDir
::
extractParameters
()
void
Command_DeckNewDir
::
extractParameters
()
{
{
Command
::
extractParameters
();
Command
::
extractParameters
();
path
=
parameters
[
"path"
];
path
=
parameters
[
"path"
];
n
ame
=
parameters
[
"name"
];
dirN
ame
=
parameters
[
"
dir_
name"
];
}
}
Command_DeckDelDir
::
Command_DeckDelDir
(
const
QString
&
_path
)
Command_DeckDelDir
::
Command_DeckDelDir
(
const
QString
&
_path
)
:
Command
(
"deck_del_dir"
),
path
(
_path
)
:
Command
(
"deck_del_dir"
),
path
(
_path
)
...
@@ -43,25 +43,25 @@ void Command_DeckDelDir::extractParameters()
...
@@ -43,25 +43,25 @@ void Command_DeckDelDir::extractParameters()
Command
::
extractParameters
();
Command
::
extractParameters
();
path
=
parameters
[
"path"
];
path
=
parameters
[
"path"
];
}
}
Command_DeckDel
::
Command_DeckDel
(
int
_
i
d
)
Command_DeckDel
::
Command_DeckDel
(
int
_
deckI
d
)
:
Command
(
"deck_del"
),
id
(
_i
d
)
:
Command
(
"deck_del"
),
deckId
(
_deckI
d
)
{
{
setParameter
(
"
id"
,
i
d
);
setParameter
(
"
deck_id"
,
deckI
d
);
}
}
void
Command_DeckDel
::
extractParameters
()
void
Command_DeckDel
::
extractParameters
()
{
{
Command
::
extractParameters
();
Command
::
extractParameters
();
i
d
=
parameters
[
"id"
].
toInt
();
deckI
d
=
parameters
[
"
deck_
id"
].
toInt
();
}
}
Command_DeckDownload
::
Command_DeckDownload
(
int
_
i
d
)
Command_DeckDownload
::
Command_DeckDownload
(
int
_
deckI
d
)
:
Command
(
"deck_download"
),
id
(
_i
d
)
:
Command
(
"deck_download"
),
deckId
(
_deckI
d
)
{
{
setParameter
(
"
id"
,
i
d
);
setParameter
(
"
deck_id"
,
deckI
d
);
}
}
void
Command_DeckDownload
::
extractParameters
()
void
Command_DeckDownload
::
extractParameters
()
{
{
Command
::
extractParameters
();
Command
::
extractParameters
();
i
d
=
parameters
[
"id"
].
toInt
();
deckI
d
=
parameters
[
"
deck_
id"
].
toInt
();
}
}
Command_ListChatChannels
::
Command_ListChatChannels
()
Command_ListChatChannels
::
Command_ListChatChannels
()
:
Command
(
"list_chat_channels"
)
:
Command
(
"list_chat_channels"
)
...
...
common/protocol_items.dat
View file @
c1b75228
0:ping
0:ping
0:login:s,username:s,password
0:login:s,username:s,password
0:deck_list
0:deck_list
0:deck_new_dir:s,path:s,name
0:deck_new_dir:s,path:s,
dir_
name
0:deck_del_dir:s,path
0:deck_del_dir:s,path
0:deck_del:i,id
0:deck_del:i,
deck_
id
0:deck_download:i,id
0:deck_download:i,
deck_
id
0:list_chat_channels
0:list_chat_channels
0:chat_join_channel:s,channel
0:chat_join_channel:s,channel
1:chat_leave_channel
1:chat_leave_channel
...
...
common/protocol_items.h
View file @
c1b75228
...
@@ -37,11 +37,11 @@ class Command_DeckNewDir : public Command {
...
@@ -37,11 +37,11 @@ class Command_DeckNewDir : public Command {
Q_OBJECT
Q_OBJECT
private:
private:
QString
path
;
QString
path
;
QString
n
ame
;
QString
dirN
ame
;
public:
public:
Command_DeckNewDir
(
const
QString
&
_path
=
QString
(),
const
QString
&
_
n
ame
=
QString
());
Command_DeckNewDir
(
const
QString
&
_path
=
QString
(),
const
QString
&
_
dirN
ame
=
QString
());
QString
getPath
()
const
{
return
path
;
}
QString
getPath
()
const
{
return
path
;
}
QString
getName
()
const
{
return
n
ame
;
}
QString
get
Dir
Name
()
const
{
return
dirN
ame
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckNewDir
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckNewDir
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckNewDir
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckNewDir
;
}
protected:
protected:
...
@@ -62,10 +62,10 @@ protected:
...
@@ -62,10 +62,10 @@ protected:
class
Command_DeckDel
:
public
Command
{
class
Command_DeckDel
:
public
Command
{
Q_OBJECT
Q_OBJECT
private:
private:
int
i
d
;
int
deckI
d
;
public:
public:
Command_DeckDel
(
int
_
i
d
=
-
1
);
Command_DeckDel
(
int
_
deckI
d
=
-
1
);
int
getId
()
const
{
return
i
d
;
}
int
get
Deck
Id
()
const
{
return
deckI
d
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckDel
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckDel
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDel
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDel
;
}
protected:
protected:
...
@@ -74,10 +74,10 @@ protected:
...
@@ -74,10 +74,10 @@ protected:
class
Command_DeckDownload
:
public
Command
{
class
Command_DeckDownload
:
public
Command
{
Q_OBJECT
Q_OBJECT
private:
private:
int
i
d
;
int
deckI
d
;
public:
public:
Command_DeckDownload
(
int
_
i
d
=
-
1
);
Command_DeckDownload
(
int
_
deckI
d
=
-
1
);
int
getId
()
const
{
return
i
d
;
}
int
get
Deck
Id
()
const
{
return
deckI
d
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckDownload
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeckDownload
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDownload
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDownload
;
}
protected:
protected:
...
...
common/server_protocolhandler.cpp
View file @
c1b75228
...
@@ -37,6 +37,11 @@ void Server_ProtocolHandler::processCommand(Command *command)
...
@@ -37,6 +37,11 @@ void Server_ProtocolHandler::processCommand(Command *command)
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
if
(
chatCommand
)
{
if
(
chatCommand
)
{
qDebug
()
<<
"received ChatCommand: channel ="
<<
chatCommand
->
getChannel
();
qDebug
()
<<
"received ChatCommand: channel ="
<<
chatCommand
->
getChannel
();
if
(
authState
==
PasswordWrong
)
{
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespLoginNeeded
));
return
;
}
Server_ChatChannel
*
channel
=
chatChannels
.
value
(
chatCommand
->
getChannel
(),
0
);
Server_ChatChannel
*
channel
=
chatChannels
.
value
(
chatCommand
->
getChannel
(),
0
);
if
(
!
channel
)
{
if
(
!
channel
)
{
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespNameNotFound
));
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespNameNotFound
));
...
@@ -48,6 +53,11 @@ void Server_ProtocolHandler::processCommand(Command *command)
...
@@ -48,6 +53,11 @@ void Server_ProtocolHandler::processCommand(Command *command)
}
}
}
else
if
(
gameCommand
)
{
}
else
if
(
gameCommand
)
{
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
if
(
authState
==
PasswordWrong
)
{
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespLoginNeeded
));
return
;
}
if
(
!
games
.
contains
(
gameCommand
->
getGameId
()))
{
if
(
!
games
.
contains
(
gameCommand
->
getGameId
()))
{
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespNameNotFound
));
sendProtocolItem
(
new
ProtocolResponse
(
gameCommand
->
getCmdId
(),
RespNameNotFound
));
return
;
return
;
...
@@ -136,6 +146,9 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
...
@@ -136,6 +146,9 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
ResponseCode
Server_ProtocolHandler
::
cmdListChatChannels
(
Command_ListChatChannels
*
/*cmd*/
)
ResponseCode
Server_ProtocolHandler
::
cmdListChatChannels
(
Command_ListChatChannels
*
/*cmd*/
)
{
{
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
Event_ListChatChannels
*
event
=
new
Event_ListChatChannels
;
Event_ListChatChannels
*
event
=
new
Event_ListChatChannels
;
QMapIterator
<
QString
,
Server_ChatChannel
*>
channelIterator
(
server
->
getChatChannels
());
QMapIterator
<
QString
,
Server_ChatChannel
*>
channelIterator
(
server
->
getChatChannels
());
while
(
channelIterator
.
hasNext
())
{
while
(
channelIterator
.
hasNext
())
{
...
@@ -150,6 +163,9 @@ ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannel
...
@@ -150,6 +163,9 @@ ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannel
ResponseCode
Server_ProtocolHandler
::
cmdChatJoinChannel
(
Command_ChatJoinChannel
*
cmd
)
ResponseCode
Server_ProtocolHandler
::
cmdChatJoinChannel
(
Command_ChatJoinChannel
*
cmd
)
{
{
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
if
(
chatChannels
.
contains
(
cmd
->
getChannel
()))
if
(
chatChannels
.
contains
(
cmd
->
getChannel
()))
return
RespContextError
;
return
RespContextError
;
...
...
servatrice/src/serversocketinterface.cpp
View file @
c1b75228
...
@@ -116,9 +116,10 @@ int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
...
@@ -116,9 +116,10 @@ int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
servatrice
->
checkSql
();
servatrice
->
checkSql
();
QSqlQuery
query
;
QSqlQuery
query
;
query
.
prepare
(
"select id from decklist_folders where id_parent = :id_parent and name = :name"
);
query
.
prepare
(
"select id from decklist_folders where id_parent = :id_parent and name = :name
and user = :user
"
);
query
.
bindValue
(
":id_parent"
,
basePathId
);
query
.
bindValue
(
":id_parent"
,
basePathId
);
query
.
bindValue
(
":name"
,
path
.
takeFirst
());
query
.
bindValue
(
":name"
,
path
.
takeFirst
());
query
.
bindValue
(
":user"
,
playerName
);
if
(
!
servatrice
->
execSqlQuery
(
query
))
if
(
!
servatrice
->
execSqlQuery
(
query
))
return
-
1
;
return
-
1
;
if
(
!
query
.
next
())
if
(
!
query
.
next
())
...
@@ -159,6 +160,9 @@ void ServerSocketInterface::deckListHelper(Response_DeckList::Directory *folder)
...
@@ -159,6 +160,9 @@ void ServerSocketInterface::deckListHelper(Response_DeckList::Directory *folder)
}
}
}
}
// CHECK AUTHENTICATION!
// Also check for every function that data belonging to other users cannot be accessed.
ResponseCode
ServerSocketInterface
::
cmdDeckList
(
Command_DeckList
*
cmd
)
ResponseCode
ServerSocketInterface
::
cmdDeckList
(
Command_DeckList
*
cmd
)
{
{
Response_DeckList
::
Directory
*
root
=
new
Response_DeckList
::
Directory
(
QString
());
Response_DeckList
::
Directory
*
root
=
new
Response_DeckList
::
Directory
(
QString
());
...
@@ -182,7 +186,7 @@ ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd)
...
@@ -182,7 +186,7 @@ ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd)
query
.
prepare
(
"insert into decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)"
);
query
.
prepare
(
"insert into decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)"
);
query
.
bindValue
(
":id_parent"
,
folderId
);
query
.
bindValue
(
":id_parent"
,
folderId
);
query
.
bindValue
(
":user"
,
playerName
);
query
.
bindValue
(
":user"
,
playerName
);
query
.
bindValue
(
":name"
,
cmd
->
getName
());
query
.
bindValue
(
":name"
,
cmd
->
get
Dir
Name
());
if
(
!
servatrice
->
execSqlQuery
(
query
))
if
(
!
servatrice
->
execSqlQuery
(
query
))
return
RespContextError
;
return
RespContextError
;
return
RespOk
;
return
RespOk
;
...
@@ -217,6 +221,20 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd)
...
@@ -217,6 +221,20 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd)
ResponseCode
ServerSocketInterface
::
cmdDeckDel
(
Command_DeckDel
*
cmd
)
ResponseCode
ServerSocketInterface
::
cmdDeckDel
(
Command_DeckDel
*
cmd
)
{
{
QSqlQuery
query
;
query
.
prepare
(
"select id from decklist_files where id = :id and user = :user"
);
query
.
bindValue
(
":id"
,
cmd
->
getDeckId
());
query
.
bindValue
(
":user"
,
playerName
);
servatrice
->
execSqlQuery
(
query
);
if
(
!
query
.
next
())
return
RespNameNotFound
;
query
.
prepare
(
"delete from decklist_files where id = :id"
);
query
.
bindValue
(
":id"
,
cmd
->
getDeckId
());
servatrice
->
execSqlQuery
(
query
);
return
RespOk
;
}
}
ResponseCode
ServerSocketInterface
::
cmdDeckUpload
(
Command_DeckUpload
*
cmd
)
ResponseCode
ServerSocketInterface
::
cmdDeckUpload
(
Command_DeckUpload
*
cmd
)
...
...
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