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
e6a419aa
Commit
e6a419aa
authored
Aug 23, 2009
by
Max-Wilhelm Bruker
Browse files
chat code
parent
120193fb
Changes
9
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/chatwidget.cpp
View file @
e6a419aa
...
@@ -2,13 +2,15 @@
...
@@ -2,13 +2,15 @@
#include
"chatwidget.h"
#include
"chatwidget.h"
#include
"client.h"
#include
"client.h"
ChannelWidget
::
ChannelWidget
(
const
QString
&
_name
,
QWidget
*
parent
)
ChannelWidget
::
ChannelWidget
(
Client
*
_client
,
const
QString
&
_name
,
QWidget
*
parent
)
:
QWidget
(
parent
),
name
(
_name
)
:
QWidget
(
parent
),
client
(
_client
),
name
(
_name
)
{
{
playerList
=
new
QListWidget
;
playerList
=
new
QListWidget
;
textEdit
=
new
QTextEdit
;
textEdit
=
new
QTextEdit
;
textEdit
->
setReadOnly
(
true
);
sayEdit
=
new
QLineEdit
;
sayEdit
=
new
QLineEdit
;
connect
(
sayEdit
,
SIGNAL
(
returnPressed
()),
this
,
SLOT
(
sendMessage
()));
QVBoxLayout
*
vbox
=
new
QVBoxLayout
;
QVBoxLayout
*
vbox
=
new
QVBoxLayout
;
vbox
->
addWidget
(
textEdit
);
vbox
->
addWidget
(
textEdit
);
...
@@ -21,6 +23,14 @@ ChannelWidget::ChannelWidget(const QString &_name, QWidget *parent)
...
@@ -21,6 +23,14 @@ ChannelWidget::ChannelWidget(const QString &_name, QWidget *parent)
setLayout
(
hbox
);
setLayout
(
hbox
);
}
}
void
ChannelWidget
::
sendMessage
()
{
if
(
sayEdit
->
text
().
isEmpty
())
return
;
client
->
chatSay
(
name
,
sayEdit
->
text
());
sayEdit
->
clear
();
}
void
ChannelWidget
::
joinEvent
(
const
QString
&
playerName
)
void
ChannelWidget
::
joinEvent
(
const
QString
&
playerName
)
{
{
textEdit
->
append
(
tr
(
"%1 has joined the channel."
).
arg
(
playerName
));
textEdit
->
append
(
tr
(
"%1 has joined the channel."
).
arg
(
playerName
));
...
@@ -102,6 +112,14 @@ void ChatWidget::chatEvent(const ChatEventData &data)
...
@@ -102,6 +112,14 @@ void ChatWidget::chatEvent(const ChatEventData &data)
case
eventChatListChannels
:
{
case
eventChatListChannels
:
{
if
(
msg
.
size
()
!=
3
)
if
(
msg
.
size
()
!=
3
)
break
;
break
;
for
(
int
i
=
0
;
i
<
channelList
->
topLevelItemCount
();
++
i
)
{
QTreeWidgetItem
*
twi
=
channelList
->
topLevelItem
(
i
);
if
(
twi
->
text
(
0
)
==
msg
[
0
])
{
twi
->
setText
(
1
,
msg
[
1
]);
twi
->
setText
(
2
,
msg
[
2
]);
return
;
}
}
channelList
->
addTopLevelItem
(
new
QTreeWidgetItem
(
QStringList
()
<<
msg
[
0
]
<<
msg
[
1
]
<<
msg
[
2
]));
channelList
->
addTopLevelItem
(
new
QTreeWidgetItem
(
QStringList
()
<<
msg
[
0
]
<<
msg
[
1
]
<<
msg
[
2
]));
break
;
break
;
}
}
...
@@ -167,7 +185,7 @@ void ChatWidget::joinFinished(ServerResponse resp)
...
@@ -167,7 +185,7 @@ void ChatWidget::joinFinished(ServerResponse resp)
PendingCommand
*
pc
=
qobject_cast
<
PendingCommand
*>
(
sender
());
PendingCommand
*
pc
=
qobject_cast
<
PendingCommand
*>
(
sender
());
QString
channelName
=
pc
->
getExtraData
();
QString
channelName
=
pc
->
getExtraData
();
ChannelWidget
*
cw
=
new
ChannelWidget
(
channelName
);
ChannelWidget
*
cw
=
new
ChannelWidget
(
client
,
channelName
);
tab
->
addTab
(
cw
,
channelName
);
tab
->
addTab
(
cw
,
channelName
);
}
}
...
...
cockatrice/src/chatwidget.h
View file @
e6a419aa
...
@@ -18,9 +18,12 @@ private:
...
@@ -18,9 +18,12 @@ private:
QListWidget
*
playerList
;
QListWidget
*
playerList
;
QTextEdit
*
textEdit
;
QTextEdit
*
textEdit
;
QLineEdit
*
sayEdit
;
QLineEdit
*
sayEdit
;
Client
*
client
;
QString
name
;
QString
name
;
private
slots
:
void
sendMessage
();
public:
public:
ChannelWidget
(
const
QString
&
_name
,
QWidget
*
parent
=
0
);
ChannelWidget
(
Client
*
_client
,
const
QString
&
_name
,
QWidget
*
parent
=
0
);
const
QString
&
getName
()
const
{
return
name
;
}
const
QString
&
getName
()
const
{
return
name
;
}
void
joinEvent
(
const
QString
&
playerName
);
void
joinEvent
(
const
QString
&
playerName
);
...
...
cockatrice/src/window_main.cpp
View file @
e6a419aa
...
@@ -70,7 +70,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
...
@@ -70,7 +70,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
aRestartGame
->
setEnabled
(
false
);
aRestartGame
->
setEnabled
(
false
);
aLeaveGame
->
setEnabled
(
false
);
aLeaveGame
->
setEnabled
(
false
);
phasesToolbar
->
setActivePhase
(
-
1
);
phasesToolbar
->
setActivePhase
(
-
1
);
phasesToolbar
->
setEnabled
(
false
);
phasesToolbar
->
hide
(
);
emit
logDisconnected
();
emit
logDisconnected
();
break
;
break
;
case
StatusLoggingIn
:
case
StatusLoggingIn
:
...
@@ -85,7 +85,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
...
@@ -85,7 +85,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
aRestartGame
->
setEnabled
(
false
);
aRestartGame
->
setEnabled
(
false
);
aLeaveGame
->
setEnabled
(
false
);
aLeaveGame
->
setEnabled
(
false
);
phasesToolbar
->
setActivePhase
(
-
1
);
phasesToolbar
->
setActivePhase
(
-
1
);
phasesToolbar
->
setEnabled
(
false
);
phasesToolbar
->
hide
(
);
view
->
hide
();
view
->
hide
();
gameSelector
->
enableGameList
();
gameSelector
->
enableGameList
();
...
@@ -94,7 +94,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
...
@@ -94,7 +94,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
}
}
case
StatusPlaying
:
case
StatusPlaying
:
chatWidget
->
disableChat
();
chatWidget
->
disableChat
();
phasesToolbar
->
s
etEnabled
(
true
);
phasesToolbar
->
s
how
(
);
view
->
show
();
view
->
show
();
break
;
break
;
default:
default:
...
@@ -313,7 +313,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
...
@@ -313,7 +313,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
viewLayout
->
addWidget
(
view
);
viewLayout
->
addWidget
(
view
);
phasesToolbar
=
new
PhasesToolbar
;
phasesToolbar
=
new
PhasesToolbar
;
phasesToolbar
->
setEnabled
(
false
);
phasesToolbar
->
hide
(
);
QHBoxLayout
*
mainLayout
=
new
QHBoxLayout
;
QHBoxLayout
*
mainLayout
=
new
QHBoxLayout
;
mainLayout
->
addWidget
(
phasesToolbar
);
mainLayout
->
addWidget
(
phasesToolbar
);
...
...
servatrice/src/chatchannel.cpp
View file @
e6a419aa
...
@@ -37,3 +37,8 @@ void ChatChannel::say(ServerSocket *player, const QString &s)
...
@@ -37,3 +37,8 @@ void ChatChannel::say(ServerSocket *player, const QString &s)
for
(
int
i
=
0
;
i
<
size
();
++
i
)
for
(
int
i
=
0
;
i
<
size
();
++
i
)
at
(
i
)
->
msg
(
str
);
at
(
i
)
->
msg
(
str
);
}
}
QString
ChatChannel
::
getChannelListLine
()
const
{
return
QString
(
"chat|list_channels|%1|%2|%3"
).
arg
(
name
).
arg
(
description
).
arg
(
size
());
}
\ No newline at end of file
servatrice/src/chatchannel.h
View file @
e6a419aa
...
@@ -20,6 +20,7 @@ public:
...
@@ -20,6 +20,7 @@ public:
void
addPlayer
(
ServerSocket
*
player
);
void
addPlayer
(
ServerSocket
*
player
);
void
removePlayer
(
ServerSocket
*
player
);
void
removePlayer
(
ServerSocket
*
player
);
void
say
(
ServerSocket
*
player
,
const
QString
&
s
);
void
say
(
ServerSocket
*
player
,
const
QString
&
s
);
QString
getChannelListLine
()
const
;
};
};
#endif
#endif
servatrice/src/server.cpp
View file @
e6a419aa
...
@@ -39,6 +39,9 @@ Server::Server(QObject *parent)
...
@@ -39,6 +39,9 @@ Server::Server(QObject *parent)
chatChannelList
<<
new
ChatChannel
(
"channel1"
,
"testchannel 1"
);
chatChannelList
<<
new
ChatChannel
(
"channel1"
,
"testchannel 1"
);
chatChannelList
<<
new
ChatChannel
(
"channel2"
,
"testchannel 2"
);
chatChannelList
<<
new
ChatChannel
(
"channel2"
,
"testchannel 2"
);
for
(
int
i
=
0
;
i
<
chatChannelList
.
size
();
++
i
)
connect
(
chatChannelList
[
i
],
SIGNAL
(
channelInfoChanged
()),
this
,
SLOT
(
broadcastChannelUpdate
()));
}
}
Server
::~
Server
()
Server
::~
Server
()
...
@@ -163,6 +166,14 @@ void Server::broadcastGameListUpdate(ServerGame *game)
...
@@ -163,6 +166,14 @@ void Server::broadcastGameListUpdate(ServerGame *game)
players
[
i
]
->
msg
(
line
);
players
[
i
]
->
msg
(
line
);
}
}
void
Server
::
broadcastChannelUpdate
()
{
QString
line
=
qobject_cast
<
ChatChannel
*>
(
sender
())
->
getChannelListLine
();
for
(
int
i
=
0
;
i
<
players
.
size
();
++
i
)
if
(
players
[
i
]
->
getAcceptsChatChannelListChanges
())
players
[
i
]
->
msg
(
line
);
}
void
Server
::
addClientToGame
(
int
gameId
,
ServerSocket
*
client
)
void
Server
::
addClientToGame
(
int
gameId
,
ServerSocket
*
client
)
{
{
ServerGame
*
game
=
getGame
(
gameId
);
ServerGame
*
game
=
getGame
(
gameId
);
...
...
servatrice/src/server.h
View file @
e6a419aa
...
@@ -38,6 +38,7 @@ private slots:
...
@@ -38,6 +38,7 @@ private slots:
void
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
);
void
addGame
(
const
QString
description
,
const
QString
password
,
const
int
maxPlayers
,
ServerSocket
*
creator
);
void
addClientToGame
(
int
gameId
,
ServerSocket
*
client
);
void
addClientToGame
(
int
gameId
,
ServerSocket
*
client
);
void
gameClosing
();
void
gameClosing
();
void
broadcastChannelUpdate
();
public:
public:
Server
(
QObject
*
parent
=
0
);
Server
(
QObject
*
parent
=
0
);
~
Server
();
~
Server
();
...
...
servatrice/src/serversocket.cpp
View file @
e6a419aa
...
@@ -243,7 +243,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdChatListChannels(const QList<QVariant
...
@@ -243,7 +243,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdChatListChannels(const QList<QVariant
{
{
QList
<
ChatChannel
*>
chatChannelList
=
server
->
getChatChannelList
();
QList
<
ChatChannel
*>
chatChannelList
=
server
->
getChatChannelList
();
for
(
int
i
=
0
;
i
<
chatChannelList
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
chatChannelList
.
size
();
++
i
)
msg
(
QString
(
"chat|list_channels|%1|%2|%3"
).
arg
(
chatChannelList
[
i
]
->
getName
()).
arg
(
chatChannelList
[
i
]
->
getDescription
()).
arg
(
chatChannelList
[
i
]
->
siz
e
())
)
;
msg
(
chatChannelList
[
i
]
->
getChannelListLin
e
());
acceptsChatChannelListChanges
=
true
;
acceptsChatChannelListChanges
=
true
;
return
ReturnMessage
::
ReturnOk
;
return
ReturnMessage
::
ReturnOk
;
...
@@ -306,6 +306,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdCreateGame(const QList<QVariant> &par
...
@@ -306,6 +306,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdCreateGame(const QList<QVariant> &par
QString
password
=
params
[
1
].
toString
();
QString
password
=
params
[
1
].
toString
();
int
maxPlayers
=
params
[
2
].
toInt
();
int
maxPlayers
=
params
[
2
].
toInt
();
acceptsGameListChanges
=
false
;
acceptsGameListChanges
=
false
;
acceptsChatChannelListChanges
=
false
;
leaveGame
();
leaveGame
();
emit
createGame
(
description
,
password
,
maxPlayers
,
this
);
emit
createGame
(
description
,
password
,
maxPlayers
,
this
);
return
ReturnMessage
::
ReturnOk
;
return
ReturnMessage
::
ReturnOk
;
...
@@ -318,6 +319,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdJoinGame(const QList<QVariant> ¶m
...
@@ -318,6 +319,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdJoinGame(const QList<QVariant> ¶m
if
(
!
server
->
checkGamePassword
(
gameId
,
password
))
if
(
!
server
->
checkGamePassword
(
gameId
,
password
))
return
ReturnMessage
::
ReturnPasswordWrong
;
return
ReturnMessage
::
ReturnPasswordWrong
;
acceptsGameListChanges
=
false
;
acceptsGameListChanges
=
false
;
acceptsChatChannelListChanges
=
false
;
leaveGame
();
leaveGame
();
emit
joinGame
(
gameId
,
this
);
emit
joinGame
(
gameId
,
this
);
return
ReturnMessage
::
ReturnOk
;
return
ReturnMessage
::
ReturnOk
;
...
...
servatrice/src/serversocket.h
View file @
e6a419aa
...
@@ -123,6 +123,7 @@ public:
...
@@ -123,6 +123,7 @@ public:
void
setPlayerId
(
int
_id
)
{
playerId
=
_id
;
}
void
setPlayerId
(
int
_id
)
{
playerId
=
_id
;
}
QString
getPlayerName
()
const
{
return
playerName
;
}
QString
getPlayerName
()
const
{
return
playerName
;
}
bool
getAcceptsGameListChanges
()
const
{
return
acceptsGameListChanges
;
}
bool
getAcceptsGameListChanges
()
const
{
return
acceptsGameListChanges
;
}
bool
getAcceptsChatChannelListChanges
()
const
{
return
acceptsChatChannelListChanges
;
}
QStringList
listCounters
()
const
;
QStringList
listCounters
()
const
;
QStringList
listZones
()
const
;
QStringList
listZones
()
const
;
void
setupZones
();
void
setupZones
();
...
...
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