author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 127 | ca70467bd0a8 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
28 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
28 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
28 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
28 | 17 |
*/ |
18 |
||
19 |
#ifndef NET_H |
|
20 |
#define NET_H |
|
21 |
||
22 |
#include <QObject> |
|
23 |
#include <QTcpSocket> |
|
24 |
#include <QRegExp> |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
25 |
#include <QStringList> |
36 | 26 |
#include <QTimer> |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
27 |
#include "team.h" |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
28 |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
85
diff
changeset
|
29 |
#define MAGIC_CHAR "\x2f" |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
30 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
31 |
struct netTeam |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
32 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
33 |
QString nick; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
34 |
QStringList hhs; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
35 |
}; |
28 | 36 |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
37 |
class GameUIConfig; |
84 | 38 |
|
28 | 39 |
class HWNet : public QObject |
40 |
{ |
|
41 |
Q_OBJECT |
|
42 |
||
43 |
public: |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
44 |
HWNet(GameUIConfig * config); |
29 | 45 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
28 | 46 |
void Disconnect(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
47 |
void JoinGame(const QString & game); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
48 |
void AddTeam(const HWTeam & team); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
49 |
void StartGame(); |
28 | 50 |
|
51 |
signals: |
|
52 |
void Connected(); |
|
53 |
void AddGame(const QString & chan); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
54 |
void EnteredGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
55 |
void FromNet(const QByteArray & buf); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
56 |
void LocalCFG(const QString & team); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
57 |
void ChangeInTeams(const QStringList & teams); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
58 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
59 |
public slots: |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
60 |
void SendNet(const QByteArray & buf); |
28 | 61 |
|
62 |
private: |
|
63 |
enum NetState { |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
64 |
nsDisconnected = 0, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
65 |
nsConnecting = 1, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
66 |
nsConnected = 3, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
67 |
nsJoining = 4, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
68 |
nsJoined = 5, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
69 |
nsStarting = 6, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
70 |
nsGaming = 7, |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
71 |
nsQuitting = 8 |
28 | 72 |
}; |
73 |
||
74 |
QTcpSocket NetSocket; |
|
75 |
NetState state; |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
76 |
QRegExp * IRCmsg_cmd_text; |
28 | 77 |
QRegExp * IRCmsg_number_param; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
78 |
QRegExp * IRCmsg_who_cmd_target; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
79 |
QRegExp * IRCmsg_who_cmd_target_text; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
80 |
QRegExp * IRCmsg_who_cmd_text; |
29 | 81 |
QString mynick; |
82 |
QString opnick; |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
83 |
QString channel; |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
85
diff
changeset
|
84 |
QString seed; |
29 | 85 |
bool isOp; |
86 |
quint32 opCount; |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
87 |
netTeam teams[5]; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
88 |
quint8 teamsCount; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
89 |
int playerscnt; |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
90 |
int configasks; |
36 | 91 |
QByteArray NetBuffer; |
92 |
QTimer * TimerFlusher; |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
93 |
GameUIConfig * config; |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
94 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
95 |
void RawSendNet(const QString & buf); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
96 |
void RawSendNet(const QByteArray & buf); |
28 | 97 |
|
125 | 98 |
void ParseLine(const QByteArray & line); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
99 |
void msgcmd_textHandler(const QString & msg); |
28 | 100 |
void msgnumber_paramHandler(const QString & msg); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
101 |
void msgwho_cmd_targetHandler(const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
102 |
void msgwho_cmd_textHandler(const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
103 |
void msgwho_cmd_target_textHandler(const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
104 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
105 |
void hwp_opmsg(const QString & who, const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
106 |
void hwp_chanmsg(const QString & who, const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
107 |
void ConfigAsked(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
108 |
void NetTeamAdded(const QString & msg); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
109 |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
85
diff
changeset
|
110 |
void RunGame(); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
111 |
|
28 | 112 |
|
113 |
private slots: |
|
114 |
void ClientRead(); |
|
115 |
void OnConnect(); |
|
116 |
void OnDisconnect(); |
|
117 |
void Perform(); |
|
118 |
void displayError(QAbstractSocket::SocketError socketError); |
|
36 | 119 |
void FlushNetBuf(); |
28 | 120 |
}; |
121 |
||
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
122 |
#define SENDCFGSTRNET(a) {\ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
123 |
QByteArray strmsg; \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
124 |
strmsg.append(a); \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
125 |
quint8 sz = strmsg.size(); \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
126 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; \ |
36 | 127 |
QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(enginemsg.toBase64()); \ |
128 |
hwp_chanmsg(mynick, _msg); \ |
|
129 |
RawSendNet(QString("PRIVMSG %1 :").arg(channel) + _msg); \ |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
130 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
131 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
132 |
#define SENDCFGSTRLOC(a) {\ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
133 |
QByteArray strmsg; \ |
126 | 134 |
strmsg.append(QString(a).toUtf8()); \ |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
135 |
quint8 sz = strmsg.size(); \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
136 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
137 |
emit FromNet(enginemsg); \ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
138 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
29
diff
changeset
|
139 |
|
28 | 140 |
#endif |