author | Medo <smaxein@googlemail.com> |
Tue, 19 Jun 2012 21:17:05 +0200 | |
changeset 7234 | 613998625a3c |
child 7269 | 5b0aeef8ba2a |
permissions | -rw-r--r-- |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
/* |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
* Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
* Copyright (c) 2012 Simeon Maxein <smaxein@googlemail.com> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
* |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
* This program is free software; you can redistribute it and/or modify |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
* the Free Software Foundation; version 2 of the License |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
* |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
* GNU General Public License for more details. |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
* |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
* along with this program; if not, write to the Free Software |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
*/ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
#include "netconn.h" |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
#include "netbase.h" |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
#include "netprotocol.h" |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
#include "../util/logging.h" |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#include "../util/util.h" |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
#include <stdbool.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
#include <stdlib.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
#include <string.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
#include <errno.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
struct _flib_netconn { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
flib_netbase *netBase; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
char *playerName; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
int netconnState; // One of the NETCONN_STATE constants |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
void (*onErrorCb)(void* context, int errorCode, const char *errorMsg); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
void *onErrorCtx; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
void (*onConnectedCb)(void *context, const char *serverMessage); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
void *onConnectedCtx; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
bool running; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
bool destroyRequested; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
}; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
static void defaultCallback_onError(void* context, int errorCode, const char *errormsg) {} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
static void defaultCallback_onConnected(void *context, const char *serverMessage) {} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
static void clearCallbacks(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
conn->onErrorCb = &defaultCallback_onError; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
conn->onConnectedCb = &defaultCallback_onConnected; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
flib_netconn *flib_netconn_create(const char *playerName, const char *host, uint16_t port) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
flib_netconn *result = NULL; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
flib_netconn *newConn = flib_calloc(1, sizeof(flib_netconn)); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
if(newConn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
newConn->netconnState = NETCONN_STATE_AWAIT_CONNECTED; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
newConn->running = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
newConn->destroyRequested = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
clearCallbacks(newConn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
newConn->netBase = flib_netbase_create(host, port); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
newConn->playerName = flib_strdupnull(playerName); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
if(newConn->netBase && newConn->playerName) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
result = newConn; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
newConn = NULL; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
flib_netconn_destroy(newConn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
return result; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
void flib_netconn_destroy(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
if(conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
if(conn->running) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
/* |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
* The function was called from a callback, so the tick function is still running |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
* and we delay the actual destruction. We ensure no further callbacks will be |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
* sent to prevent surprises. |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
*/ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
clearCallbacks(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
conn->destroyRequested = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
86 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
87 |
flib_netbase_destroy(conn->netBase); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
88 |
free(conn->playerName); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
89 |
free(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
92 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
void flib_netconn_onError(flib_netconn *conn, void (*callback)(void *context, int errorCode, const char *errorMsg), void* context) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
95 |
if(!conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
96 |
flib_log_e("null parameter in flib_netconn_onError"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
conn->onErrorCb = callback ? callback : &defaultCallback_onError; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
99 |
conn->onErrorCtx = context; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
100 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
101 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
102 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
103 |
void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context, const char *serverMessage), void* context) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
if(!conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
flib_log_e("null parameter in flib_netconn_onConnected"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
106 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
conn->onConnectedCb = callback ? callback : &defaultCallback_onConnected; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
108 |
conn->onConnectedCtx = context; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
109 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
111 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
112 |
static void flib_netconn_wrappedtick(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
113 |
flib_netmsg *netmsg; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
114 |
flib_netbase *net = conn->netBase; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
115 |
bool exit = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
116 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
117 |
while(!exit && !conn->destroyRequested && (netmsg=flib_netbase_recv_message(conn->netBase))) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
if(netmsg->partCount==0) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
flib_log_w("Empty server message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
120 |
continue; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
123 |
const char *cmd = netmsg->parts[0]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
125 |
if (!strcmp(cmd, "NICK") && netmsg->partCount>=2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
126 |
free(conn->playerName); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
127 |
conn->playerName = flib_strdupnull(netmsg->parts[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
128 |
if(!conn->playerName) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
129 |
// TODO handle error |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
130 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
131 |
// TODO callback? |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
132 |
} else if (!strcmp(cmd, "PROTO")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
133 |
// The server just echoes this back apparently |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
134 |
} else if (!strcmp(cmd, "ERROR")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
135 |
// TODO: onErrorMessage? |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
136 |
if (netmsg->partCount == 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
137 |
conn->onErrorCb(conn->onErrorCtx, NETCONN_ERROR_FROM_SERVER, netmsg->parts[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
138 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
139 |
conn->onErrorCb(conn->onErrorCtx, NETCONN_ERROR_FROM_SERVER, "Unknown Error"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
140 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
141 |
} else if(!strcmp(cmd, "WARNING")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
142 |
// TODO: onWarnMessage? |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
143 |
if (netmsg->partCount == 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
144 |
conn->onErrorCb(conn->onErrorCtx, NETCONN_ERROR_FROM_SERVER, netmsg->parts[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
145 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
146 |
conn->onErrorCb(conn->onErrorCtx, NETCONN_ERROR_FROM_SERVER, "Unknown Warning"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
147 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
148 |
} else if(!strcmp(cmd, "CONNECTED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
149 |
if(netmsg->partCount<3 || atol(netmsg->parts[2])<MIN_SERVER_VERSION) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
150 |
flib_log_w("Server too old"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
151 |
flib_netbase_sendf(net, "%s\n%s\n\n", "QUIT", "Server too old"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
152 |
// TODO actually disconnect? |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
153 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
154 |
conn->onErrorCb(conn->onErrorCtx, NETCONN_ERROR_SERVER_TOO_OLD, "Server too old"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
155 |
exit = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
156 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
157 |
flib_netbase_sendf(net, "%s\n%s\n\n", "NICK", conn->playerName); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
158 |
flib_netbase_sendf(net, "%s\n%i\n\n", "PROTO", (int)PROTOCOL_VERSION); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
159 |
conn->netconnState = NETCONN_STATE_LOBBY; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
160 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
161 |
} else if(!strcmp(cmd, "PING")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
162 |
if (netmsg->partCount > 1) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
163 |
flib_netbase_sendf(net, "%s\n%s\n\n", "PONG", netmsg->parts[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
164 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
165 |
flib_netbase_sendf(net, "%s\n\n", "PONG"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
166 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
167 |
} else if(!strcmp(cmd, "ROOMS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
168 |
if(netmsg->partCount % 8 != 1) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
169 |
flib_log_w("Net: Malformed ROOMS message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
170 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
171 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
172 |
//QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
173 |
//tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
174 |
//m_roomsListModel->setRoomsList(tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
175 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
176 |
} else if (!strcmp(cmd, "SERVER_MESSAGE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
177 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
178 |
flib_log_w("Net: Empty SERVERMESSAGE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
179 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
180 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
181 |
// emit serverMessage(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
182 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
183 |
} else if (!strcmp(cmd, "CHAT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
184 |
if(netmsg->partCount < 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
185 |
flib_log_w("Net: Empty CHAT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
186 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
187 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
188 |
// if (netClientState == InLobby) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
189 |
// emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
190 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
191 |
// emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
192 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
193 |
} else if (!strcmp(cmd, "INFO")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
194 |
if(netmsg->partCount < 5) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
195 |
flib_log_w("Net: Malformed INFO message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
196 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
198 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
199 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
200 |
// if (netClientState == InLobby) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
201 |
// emit chatStringLobby(tmp.join("\n").prepend('\x01')); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
202 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
203 |
// emit chatStringFromNet(tmp.join("\n").prepend('\x01')); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
204 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
205 |
} else if(!strcmp(cmd, "SERVER_VARS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
206 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
207 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
208 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
209 |
// while (tmp.size() >= 2) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
210 |
// { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
211 |
// if(tmp[0] == "MOTD_NEW") emit serverMessageNew(tmp[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
212 |
// else if(tmp[0] == "MOTD_OLD") emit serverMessageOld(tmp[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
213 |
// else if(tmp[0] == "LATEST_PROTO") emit latestProtocolVar(tmp[1].toInt()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
214 |
// |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
215 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
216 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
217 |
// } |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
218 |
} else if (!strcmp(cmd, "CLIENT_FLAGS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
219 |
if(netmsg->partCount < 3 || strlen(netmsg->parts[1]) < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
220 |
flib_log_w("Net: Malformed CLIENT_FLAGS message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
221 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
222 |
const char *flags = netmsg->parts[1]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
223 |
bool setFlag = flags[0] == '+'; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
224 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
225 |
for(int i=1; flags[i]; i++) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
226 |
switch(flags[i]) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
227 |
case 'r': |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
228 |
for(int j = 2; j < netmsg->partCount; ++j) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
229 |
if (!strcmp(conn->playerName, netmsg->parts[i])) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
230 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
231 |
// if (isChief && !setFlag) ToggleReady(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
232 |
// else emit setMyReadyStatus(setFlag); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
233 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
234 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
235 |
// emit setReadyStatus(lst[i], setFlag); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
236 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
237 |
break; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
238 |
default: |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
239 |
flib_log_w("Net: Unknown flag %c in CLIENT_FLAGS message", flags[i]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
240 |
break; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
241 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
242 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
243 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
244 |
} else if (!strcmp(cmd, "ADD_TEAM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
245 |
if(netmsg->partCount != 24) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
246 |
flib_log_w("Net: Bad ADD_TEAM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
247 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
248 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
249 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
250 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
251 |
// emit AddNetTeam(tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
252 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
253 |
} else if (!strcmp(cmd, "REMOVE_TEAM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
254 |
if(netmsg->partCount != 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
255 |
flib_log_w("Net: Bad REMOVETEAM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
256 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
257 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
258 |
// emit RemoveNetTeam(HWTeam(lst[1])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
259 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
260 |
} else if(!strcmp(cmd, "ROOMABANDONED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
261 |
conn->netconnState = NETCONN_STATE_LOBBY; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
262 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
263 |
// askRoomsList(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
264 |
// emit LeftRoom(tr("Room destroyed")); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
265 |
} else if(!strcmp(cmd, "KICKED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
266 |
conn->netconnState = NETCONN_STATE_LOBBY; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
267 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
268 |
// askRoomsList(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
269 |
// emit LeftRoom(tr("You got kicked")); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
270 |
} else if(!strcmp(cmd, "JOINED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
271 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
272 |
flib_log_w("Net: Bad JOINED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
273 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
274 |
for(int i = 1; i < netmsg->partCount; ++i) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
275 |
{ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
276 |
bool isMe = !strcmp(conn->playerName, netmsg->parts[i]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
277 |
if (isMe) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
278 |
conn->netconnState = NETCONN_STATE_ROOM; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
279 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
280 |
// emit EnteredGame(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
281 |
// emit roomMaster(isChief); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
282 |
// if (isChief) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
283 |
// emit configAsked(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
284 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
285 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
286 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
287 |
// emit nickAdded(lst[i], isChief && !isMe)); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
288 |
// emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
289 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
290 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
291 |
} else if(!strcmp(cmd, "LOBBY:JOINED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
292 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
293 |
flib_log_w("Net: Bad JOINED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
294 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
295 |
for(int i = 1; i < netmsg->partCount; ++i) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
296 |
{ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
297 |
bool isMe = !strcmp(conn->playerName, netmsg->parts[i]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
298 |
if (isMe) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
299 |
conn->netconnState = NETCONN_STATE_LOBBY; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
300 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
301 |
// RawSendNet(QString("LIST")); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
302 |
// emit connected(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
303 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
304 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
305 |
// emit nickAddedLobby(lst[i], false); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
306 |
// emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
307 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
308 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
309 |
} else if(!strcmp(cmd, "LEFT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
310 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
311 |
flib_log_w("Net: Bad LEFT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
312 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
313 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
314 |
// emit nickRemoved(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
315 |
// if (netmsg->partCount < 3) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
316 |
// emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
317 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
318 |
// emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
319 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
320 |
} else if(!strcmp(cmd, "ROOM") && netmsg->partCount >= 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
321 |
const char *subcmd = netmsg->parts[1]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
322 |
if(!strcmp(subcmd, "ADD") && netmsg->partCount == 10) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
323 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
324 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
325 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
326 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
327 |
// |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
328 |
// m_roomsListModel->addRoom(tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
329 |
} else if(!strcmp(subcmd, "UPD") && netmsg->partCount == 11) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
330 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
331 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
332 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
333 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
334 |
// |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
335 |
// QString roomName = tmp.takeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
336 |
// m_roomsListModel->updateRoom(roomName, tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
337 |
} else if(!strcmp(subcmd, "DEL") && netmsg->partCount == 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
338 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
339 |
// m_roomsListModel->removeRoom(lst[2]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
340 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
341 |
flib_log_w("Net: Unknown or malformed ROOM subcommand: %s", subcmd); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
342 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
343 |
} else if(!strcmp(cmd, "LOBBY:LEFT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
344 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
345 |
flib_log_w("Net: Bad LOBBY:LEFT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
346 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
347 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
348 |
// emit nickRemovedLobby(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
349 |
// if (netmsg->partCount < 3) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
350 |
// emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
351 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
352 |
// emit chatStringLobby(lst[1], tr("%1 *** %2 has left (%3)").arg('\x03').arg("|nick|", lst[2])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
353 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
354 |
} else if (!strcmp(cmd, "RUN_GAME")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
355 |
conn->netconnState = NETCONN_STATE_INGAME; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
356 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
357 |
// emit AskForRunGame(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
358 |
} else if (!strcmp(cmd, "ASKPASSWORD")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
359 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
360 |
// emit AskForPassword(mynick); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
361 |
} else if (!strcmp(cmd, "NOTICE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
362 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
363 |
flib_log_w("Net: Bad NOTICE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
364 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
365 |
errno = 0; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
366 |
long n = strtol(netmsg->parts[1], NULL, 10); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
367 |
if(errno) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
368 |
flib_log_w("Net: Bad NOTICE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
369 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
370 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
371 |
// handleNotice(n); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
372 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
373 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
374 |
} else if (!strcmp(cmd, "TEAM_ACCEPTED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
375 |
if (netmsg->partCount != 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
376 |
flib_log_w("Net: Bad TEAM_ACCEPTED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
377 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
378 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
379 |
// emit TeamAccepted(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
380 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
381 |
} else if (!strcmp(cmd, "CFG")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
382 |
if(netmsg->partCount < 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
383 |
flib_log_w("Net: Bad CFG message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
384 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
385 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
386 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
387 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
388 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
389 |
// if (lst[1] == "SCHEME") |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
390 |
// emit netSchemeConfig(tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
391 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
392 |
// emit paramChanged(lst[1], tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
393 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
394 |
} else if (!strcmp(cmd, "HH_NUM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
395 |
if (netmsg->partCount != 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
396 |
flib_log_w("Net: Bad TEAM_ACCEPTED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
397 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
398 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
399 |
// HWTeam tmptm(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
400 |
// tmptm.setNumHedgehogs(lst[2].toUInt()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
401 |
// emit hhnumChanged(tmptm); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
402 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
403 |
} else if (!strcmp(cmd, "TEAM_COLOR")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
404 |
if (netmsg->partCount != 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
405 |
flib_log_w("Net: Bad TEAM_COLOR message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
406 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
407 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
408 |
// HWTeam tmptm(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
409 |
// tmptm.setColor(lst[2].toInt()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
410 |
// emit teamColorChanged(tmptm); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
411 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
412 |
} else if (!strcmp(cmd, "EM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
413 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
414 |
flib_log_w("Net: Bad EM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
415 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
416 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
417 |
// for(int i = 1; i < netmsg->partCount; ++i) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
418 |
// QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
419 |
// emit FromNet(em); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
420 |
// } |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
421 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
422 |
} else if (!strcmp(cmd, "BYE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
423 |
if (netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
424 |
flib_log_w("Net: Bad BYE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
425 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
426 |
if (!strcmp(netmsg->parts[1], "Authentication failed")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
427 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
428 |
//emit AuthFailed(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
429 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
430 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
431 |
// m_game_connected = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
432 |
// Disconnect(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
433 |
// emit disconnected(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
434 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
435 |
} else if (!strcmp(cmd, "ADMIN_ACCESS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
436 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
437 |
// emit adminAccess(true); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
438 |
} else if (!strcmp(cmd, "ROOM_CONTROL_ACCESS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
439 |
if (netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
440 |
flib_log_w("Net: Bad ROOM_CONTROL_ACCESS message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
441 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
442 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
443 |
// isChief = (lst[1] != "0"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
444 |
// emit roomMaster(isChief); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
445 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
446 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
447 |
flib_log_w("Unknown server command: %s", cmd); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
448 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
449 |
flib_netmsg_destroy(netmsg); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
450 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
451 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
452 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
453 |
void flib_netconn_tick(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
454 |
if(!conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
455 |
flib_log_e("null parameter in flib_netconn_tick"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
456 |
} else if(conn->running) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
457 |
flib_log_w("Call to flib_netconn_tick from a callback"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
458 |
} else if(conn->netconnState == NETCONN_STATE_DISCONNECTED) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
459 |
flib_log_w("Call to flib_netconn_tick, but we are already done."); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
460 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
461 |
conn->running = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
462 |
flib_netconn_wrappedtick(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
463 |
conn->running = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
464 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
465 |
if(conn->destroyRequested) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
466 |
flib_netconn_destroy(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
467 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
468 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
469 |
} |