author | Medo <smaxein@googlemail.com> |
Thu, 21 Jun 2012 21:32:12 +0200 | |
changeset 7269 | 5b0aeef8ba2a |
parent 7234 | 613998625a3c |
child 7271 | 5608ac657362 |
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" |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
26 |
#include "../model/roomlist.h" |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
27 |
#include "../md5/md5.h" |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
#include <stdbool.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
#include <stdlib.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
#include <string.h> |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
#include <errno.h> |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
33 |
#include <ctype.h> |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
struct _flib_netconn { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
flib_netbase *netBase; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
char *playerName; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
38 |
flib_cfg_meta *metaCfg; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
39 |
flib_roomlist *roomList; |
7234
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 |
int netconnState; // One of the NETCONN_STATE constants |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
43 |
bool isAdmin; // Player is server administrator |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
44 |
bool isChief; // Player can modify the current room |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
45 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
46 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
47 |
void (*onMessageCb)(void *context, int msgtype, const char *msg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
48 |
void *onMessageCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
49 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
50 |
void (*onConnectedCb)(void *context); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
51 |
void *onConnectedCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
52 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
53 |
void (*onDisconnectedCb)(void *context, int reason, const char *message); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
54 |
void *onDisconnectedCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
55 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
56 |
void (*onRoomAddCb)(void *context, const flib_roomlist_room *room); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
57 |
void *onRoomAddCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
58 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
59 |
void (*onRoomDeleteCb)(void *context, const char *name); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
60 |
void *onRoomDeleteCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
61 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
62 |
void (*onRoomUpdateCb)(void *context, const char *oldName, const flib_roomlist_room *room); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
63 |
void *onRoomUpdateCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
64 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
65 |
void (*onChatCb)(void *context, const char *nick, const char *msg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
66 |
void *onChatCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
67 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
68 |
void (*onLobbyJoinCb)(void *context, const char *nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
69 |
void *onLobbyJoinCtx; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
71 |
void (*onLobbyLeaveCb)(void *context, const char *nick, const char *partMessage); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
72 |
void *onLobbyLeaveCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
73 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
74 |
void (*onRoomJoinCb)(void *context, const char *nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
75 |
void *onRoomJoinCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
76 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
77 |
void (*onRoomLeaveCb)(void *context, const char *nick, const char *partMessage); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
78 |
void *onRoomLeaveCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
79 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
80 |
void (*onNickTakenCb)(void *context, const char *nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
81 |
void *onNickTakenCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
82 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
83 |
void (*onNickAcceptCb)(void *context, const char *nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
84 |
void *onNickAcceptCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
85 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
86 |
void (*onPasswordRequestCb)(void *context, const char *nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
87 |
void *onPasswordRequestCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
88 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
89 |
void (*onRoomChiefStatusCb)(void *context, bool isChief); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
90 |
void *onRoomChiefStatusCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
91 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
92 |
void (*onReadyStateCb)(void *context, const char *nick, bool ready); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
93 |
void *onReadyStateCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
94 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
95 |
void (*onEnterRoomCb)(void *context, bool chief); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
96 |
void *onEnterRoomCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
97 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
98 |
void (*onLeaveRoomCb)(void *context, int reason, const char *message); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
99 |
void *onLeaveRoomCtx; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
100 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
101 |
void (*onTeamAddCb)(void *context, flib_team *team); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
102 |
void *onTeamAddCtx; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
103 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
bool running; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
105 |
bool destroyRequested; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
106 |
}; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
108 |
static void defaultCallback_onMessage(void *context, int msgtype, const char *msg) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
109 |
flib_log_i("Net: [%i] %s", msgtype, msg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
110 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
111 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
112 |
static void defaultCallback_void(void *context) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
113 |
static void defaultCallback_bool(void *context, bool isChief) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
114 |
static void defaultCallback_str(void *context, const char *str) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
115 |
static void defaultCallback_int_str(void *context, int i, const char *str) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
116 |
static void defaultCallback_str_str(void *context, const char *str1, const char *str2) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
117 |
static void defaultCallback_str_bool(void *context, const char *str, bool b) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
118 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
119 |
static void defaultCallback_onRoomAdd(void *context, const flib_roomlist_room *room) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
120 |
static void defaultCallback_onRoomUpdate(void *context, const char *oldName, const flib_roomlist_room *room) {} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
121 |
static void defaultCallback_onChat(void *context, const char *nick, const char *msg) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
122 |
flib_log_i("%s: %s", nick, msg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
123 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
125 |
// Change the name by suffixing it with a number. If it already ends in a number, increase that number by 1. |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
126 |
static void defaultCallback_onNickTaken(void *context, const char *requestedNick) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
127 |
flib_netconn *conn = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
128 |
size_t namelen = strlen(requestedNick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
129 |
int digits = 0; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
130 |
while(digits<namelen && isdigit(requestedNick[namelen-1-digits])) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
131 |
digits++; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
132 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
133 |
long suffix = 0; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
134 |
if(digits>0) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
135 |
suffix = atol(requestedNick+namelen-digits)+1; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
136 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
137 |
char *newPlayerName = flib_asprintf("%.*s%li", namelen-digits, requestedNick, suffix); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
138 |
if(newPlayerName) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
139 |
flib_netconn_send_nick(conn, newPlayerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
140 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
141 |
flib_netconn_send_quit(conn, "Nick already taken."); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
142 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
143 |
free(newPlayerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
144 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
145 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
146 |
// Default behavior: Quit |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
147 |
static void defaultCallback_onPasswordRequest(void *context, const char *requestedNick) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
148 |
flib_netconn_send_quit((flib_netconn*)context, "Authentication failed"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
149 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
150 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
151 |
static void defaultCallback_onTeamAdd(void *context, flib_team *team) {} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
152 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
153 |
static void clearCallbacks(flib_netconn *conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
154 |
flib_netconn_onMessage(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
155 |
flib_netconn_onConnected(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
156 |
flib_netconn_onDisconnected(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
157 |
flib_netconn_onRoomAdd(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
158 |
flib_netconn_onRoomDelete(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
159 |
flib_netconn_onRoomUpdate(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
160 |
flib_netconn_onChat(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
161 |
flib_netconn_onLobbyJoin(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
162 |
flib_netconn_onLobbyLeave(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
163 |
flib_netconn_onRoomJoin(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
164 |
flib_netconn_onRoomLeave(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
165 |
flib_netconn_onNickTaken(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
166 |
flib_netconn_onNickAccept(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
167 |
flib_netconn_onPasswordRequest(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
168 |
flib_netconn_onRoomChiefStatus(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
169 |
flib_netconn_onReadyStateCb(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
170 |
flib_netconn_onEnterRoomCb(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
171 |
flib_netconn_onTeamAddCb(conn, NULL, NULL); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
172 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
173 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
174 |
flib_netconn *flib_netconn_create(const char *playerName, flib_cfg_meta *metacfg, const char *host, uint16_t port) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
175 |
flib_netconn *result = NULL; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
176 |
if(!playerName || !metacfg || !host) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
177 |
flib_log_e("null parameter in flib_netconn_create"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
178 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
179 |
flib_netconn *newConn = flib_calloc(1, sizeof(flib_netconn)); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
180 |
if(newConn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
181 |
newConn->netconnState = NETCONN_STATE_CONNECTING; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
182 |
newConn->isAdmin = false; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
183 |
newConn->isChief = false; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
184 |
newConn->metaCfg = flib_cfg_meta_retain(metacfg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
185 |
newConn->roomList = flib_roomlist_create(); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
186 |
newConn->running = false; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
187 |
newConn->destroyRequested = false; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
188 |
clearCallbacks(newConn); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
189 |
newConn->netBase = flib_netbase_create(host, port); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
190 |
newConn->playerName = flib_strdupnull(playerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
191 |
if(newConn->netBase && newConn->playerName && newConn->roomList) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
192 |
result = newConn; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
193 |
newConn = NULL; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
194 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
195 |
} |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
196 |
flib_netconn_destroy(newConn); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
197 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
198 |
return result; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
199 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
200 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
201 |
void flib_netconn_destroy(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
202 |
if(conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
203 |
if(conn->running) { |
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 |
* 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
|
206 |
* 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
|
207 |
* sent to prevent surprises. |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
208 |
*/ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
209 |
clearCallbacks(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
210 |
conn->destroyRequested = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
211 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
212 |
flib_netbase_destroy(conn->netBase); |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
213 |
flib_cfg_meta_release(conn->metaCfg); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
214 |
flib_roomlist_destroy(conn->roomList); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
215 |
free(conn->playerName); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
216 |
free(conn); |
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 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
219 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
220 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
221 |
const flib_roomlist *flib_netconn_get_roomlist(flib_netconn *conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
222 |
const flib_roomlist *result = NULL; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
223 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
224 |
flib_log_e("null parameter in flib_netconn_get_roomlist"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
225 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
226 |
result = conn->roomList; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
227 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
228 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
229 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
230 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
231 |
bool flib_netconn_is_chief(flib_netconn *conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
232 |
bool result = false; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
233 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
234 |
flib_log_e("null parameter in flib_netconn_is_chief"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
235 |
} else if(conn->netconnState == NETCONN_STATE_ROOM || conn->netconnState == NETCONN_STATE_INGAME) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
236 |
result = conn->isChief; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
237 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
238 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
239 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
240 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
241 |
int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
242 |
int result = -1; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
243 |
if(!conn) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
244 |
flib_log_e("null parameter in flib_netconn_send_quit"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
245 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
246 |
result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "QUIT", quitmsg ? quitmsg : "User quit"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
247 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
248 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
249 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
250 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
251 |
int flib_netconn_send_chat(flib_netconn *conn, const char *chat) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
252 |
int result = -1; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
253 |
if(!conn || !chat) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
254 |
flib_log_e("null parameter in flib_netconn_send_chat"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
255 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
256 |
result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "CHAT", chat); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
257 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
258 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
259 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
260 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
261 |
int flib_netconn_send_nick(flib_netconn *conn, const char *nick) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
262 |
int result = -1; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
263 |
if(!conn || !nick) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
264 |
flib_log_e("null parameter in flib_netconn_send_nick"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
265 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
266 |
char *tmpName = flib_strdupnull(nick); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
267 |
if(tmpName) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
268 |
if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
269 |
free(conn->playerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
270 |
conn->playerName = tmpName; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
271 |
tmpName = NULL; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
272 |
result = 0; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
273 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
274 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
275 |
free(tmpName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
276 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
277 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
278 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
279 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
280 |
int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
281 |
int result = -1; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
282 |
if(!conn || !latin1Passwd) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
283 |
flib_log_e("null parameter in flib_netconn_send_password"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
284 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
285 |
md5_state_t md5state; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
286 |
uint8_t md5bytes[16]; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
287 |
char md5hex[33]; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
288 |
md5_init(&md5state); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
289 |
md5_append(&md5state, (unsigned char*)latin1Passwd, strlen(latin1Passwd)); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
290 |
md5_finish(&md5state, md5bytes); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
291 |
for(int i=0;i<sizeof(md5bytes); i++) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
292 |
// Needs to be lowercase - server checks case sensitive |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
293 |
snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
294 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
295 |
result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "PASSWORD", md5hex); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
296 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
297 |
return result; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
298 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
299 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
300 |
/* |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
301 |
* Callback registration functions |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
302 |
*/ |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
303 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
304 |
void flib_netconn_onMessage(flib_netconn *conn, void (*callback)(void *context, int msgtype, const char *msg), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
305 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
306 |
flib_log_e("null parameter in flib_netconn_onMessage"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
307 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
308 |
conn->onMessageCb = callback ? callback : &defaultCallback_onMessage; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
309 |
conn->onMessageCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
310 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
311 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
312 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
313 |
void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
314 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
315 |
flib_log_e("null parameter in flib_netconn_onConnected"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
316 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
317 |
conn->onConnectedCb = callback ? callback : &defaultCallback_void; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
318 |
conn->onConnectedCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
319 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
320 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
321 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
322 |
void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
323 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
324 |
flib_log_e("null parameter in flib_netconn_onDisconnected"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
325 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
326 |
conn->onDisconnectedCb = callback ? callback : &defaultCallback_int_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
327 |
conn->onDisconnectedCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
328 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
329 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
330 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
331 |
void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_roomlist_room *room), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
332 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
333 |
flib_log_e("null parameter in flib_netconn_onRoomAdd"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
334 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
335 |
conn->onRoomAddCb = callback ? callback : &defaultCallback_onRoomAdd; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
336 |
conn->onRoomAddCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
337 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
338 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
339 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
340 |
void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
341 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
342 |
flib_log_e("null parameter in flib_netconn_onRoomDelete"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
343 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
344 |
conn->onRoomDeleteCb = callback ? callback : &defaultCallback_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
345 |
conn->onRoomDeleteCtx = context; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
346 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
347 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
348 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
349 |
void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_roomlist_room *room), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
350 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
351 |
flib_log_e("null parameter in flib_netconn_onRoomUpdate"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
352 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
353 |
conn->onRoomUpdateCb = callback ? callback : &defaultCallback_onRoomUpdate; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
354 |
conn->onRoomUpdateCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
355 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
356 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
357 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
358 |
void flib_netconn_onChat(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *msg), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
359 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
360 |
flib_log_e("null parameter in flib_netconn_onChat"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
361 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
362 |
conn->onChatCb = callback ? callback : &defaultCallback_onChat; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
363 |
conn->onChatCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
364 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
365 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
366 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
367 |
void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
368 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
369 |
flib_log_e("null parameter in flib_netconn_onLobbyJoin"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
370 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
371 |
conn->onLobbyJoinCb = callback ? callback : &defaultCallback_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
372 |
conn->onLobbyJoinCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
373 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
374 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
375 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
376 |
void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMsg), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
377 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
378 |
flib_log_e("null parameter in flib_netconn_onLobbyLeave"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
379 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
380 |
conn->onLobbyLeaveCb = callback ? callback : &defaultCallback_str_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
381 |
conn->onLobbyLeaveCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
382 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
383 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
384 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
385 |
void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
386 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
387 |
flib_log_e("null parameter in flib_netconn_onRoomJoin"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
388 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
389 |
conn->onRoomJoinCb = callback ? callback : &defaultCallback_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
390 |
conn->onRoomJoinCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
391 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
392 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
393 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
394 |
void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
395 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
396 |
flib_log_e("null parameter in flib_netconn_onRoomLeave"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
397 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
398 |
conn->onRoomLeaveCb = callback ? callback : &defaultCallback_str_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
399 |
conn->onRoomLeaveCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
400 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
401 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
402 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
403 |
void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
404 |
if(!conn) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
405 |
flib_log_e("null parameter in flib_netconn_onNickTaken"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
406 |
} else if(!callback) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
407 |
conn->onNickTakenCb = &defaultCallback_onNickTaken; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
408 |
conn->onNickTakenCtx = conn; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
409 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
410 |
conn->onNickTakenCb = callback; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
411 |
conn->onNickTakenCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
412 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
413 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
414 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
415 |
void flib_netconn_onNickAccept(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
416 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
417 |
flib_log_e("null parameter in flib_netconn_onNickAccept"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
418 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
419 |
conn->onNickAcceptCb = callback ? callback : &defaultCallback_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
420 |
conn->onNickAcceptCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
421 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
422 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
423 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
424 |
void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
425 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
426 |
flib_log_e("null parameter in flib_netconn_onPasswordRequest"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
427 |
} else if(!callback) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
428 |
conn->onPasswordRequestCb = &defaultCallback_onPasswordRequest; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
429 |
conn->onPasswordRequestCtx = conn; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
430 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
431 |
conn->onPasswordRequestCb = callback; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
432 |
conn->onPasswordRequestCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
433 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
434 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
435 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
436 |
void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
437 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
438 |
flib_log_e("null parameter in flib_netconn_onRoomChiefStatus"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
439 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
440 |
conn->onRoomChiefStatusCb = callback ? callback : &defaultCallback_bool; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
441 |
conn->onRoomChiefStatusCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
442 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
443 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
444 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
445 |
void flib_netconn_onReadyStateCb(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
446 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
447 |
flib_log_e("null parameter in flib_netconn_onReadyStateCb"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
448 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
449 |
conn->onReadyStateCb = callback ? callback : &defaultCallback_str_bool; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
450 |
conn->onReadyStateCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
451 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
452 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
453 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
454 |
void flib_netconn_onEnterRoomCb(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
455 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
456 |
flib_log_e("null parameter in flib_netconn_onEnterRoomCb"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
457 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
458 |
conn->onEnterRoomCb = callback ? callback : &defaultCallback_bool; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
459 |
conn->onEnterRoomCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
460 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
461 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
462 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
463 |
void flib_netconn_onLeaveRoomCb(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
464 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
465 |
flib_log_e("null parameter in flib_netconn_onLeaveRoomCb"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
466 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
467 |
conn->onLeaveRoomCb = callback ? callback : &defaultCallback_int_str; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
468 |
conn->onLeaveRoomCtx = context; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
469 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
470 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
471 |
|
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
472 |
void flib_netconn_onTeamAddCb(flib_netconn *conn, void (*callback)(void *context, flib_team *team), void *context) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
473 |
if(!conn) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
474 |
flib_log_e("null parameter in flib_netconn_onTeamAddCb"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
475 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
476 |
conn->onTeamAddCb = callback ? callback : &defaultCallback_onTeamAdd; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
477 |
conn->onTeamAddCtx = context; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
478 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
479 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
480 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
481 |
static void flib_netconn_wrappedtick(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
482 |
flib_netmsg *netmsg; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
483 |
flib_netbase *net = conn->netBase; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
484 |
bool exit = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
485 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
486 |
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
|
487 |
if(netmsg->partCount==0) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
488 |
flib_log_w("Empty server message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
489 |
continue; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
490 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
491 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
492 |
if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
493 |
char *buf = flib_join(netmsg->parts, netmsg->partCount, "|"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
494 |
if(buf) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
495 |
flib_log_d("[Net In]%s", buf); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
496 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
497 |
free(buf); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
498 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
499 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
500 |
const char *cmd = netmsg->parts[0]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
501 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
502 |
if (!strcmp(cmd, "NICK") && netmsg->partCount>=2) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
503 |
if(netmsg->partCount<2) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
504 |
flib_log_w("Net: Malformed NICK message"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
505 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
506 |
free(conn->playerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
507 |
conn->playerName = flib_strdupnull(netmsg->parts[1]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
508 |
if(!conn->playerName) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
509 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
510 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Out of memory"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
511 |
exit = true; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
512 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
513 |
conn->onNickAcceptCb(conn->onNickAcceptCtx, conn->playerName); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
514 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
515 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
516 |
} else if (!strcmp(cmd, "PROTO")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
517 |
// The server just echoes this back apparently |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
518 |
} else if (!strcmp(cmd, "ERROR")) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
519 |
if (netmsg->partCount >= 2) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
520 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, netmsg->parts[1]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
521 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
522 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, "Unknown Error"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
523 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
524 |
} else if(!strcmp(cmd, "WARNING")) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
525 |
if (netmsg->partCount >= 2) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
526 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, netmsg->parts[1]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
527 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
528 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, "Unknown Warning"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
529 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
530 |
} else if(!strcmp(cmd, "CONNECTED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
531 |
if(netmsg->partCount<3 || atol(netmsg->parts[2])<MIN_SERVER_VERSION) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
532 |
flib_log_w("Net: Server too old"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
533 |
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
|
534 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
535 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_SERVER_TOO_OLD, "Server too old"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
536 |
exit = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
537 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
538 |
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
|
539 |
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
|
540 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
541 |
} else if(!strcmp(cmd, "PING")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
542 |
if (netmsg->partCount > 1) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
543 |
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
|
544 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
545 |
flib_netbase_sendf(net, "%s\n\n", "PONG"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
546 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
547 |
} else if(!strcmp(cmd, "ROOMS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
548 |
if(netmsg->partCount % 8 != 1) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
549 |
flib_log_w("Net: Malformed ROOMS message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
550 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
551 |
flib_roomlist_clear(conn->roomList); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
552 |
for(int i=1; i<netmsg->partCount; i+=8) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
553 |
if(flib_roomlist_add(conn->roomList, netmsg->parts+i)) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
554 |
flib_log_e("Error adding room to list in ROOMS message"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
555 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
556 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
557 |
if(conn->netconnState == NETCONN_STATE_CONNECTING) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
558 |
// We delay the "connected" callback until now to ensure the room list is avaliable. |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
559 |
conn->onConnectedCb(conn->onConnectedCtx); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
560 |
conn->netconnState = NETCONN_STATE_LOBBY; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
561 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
562 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
563 |
} else if (!strcmp(cmd, "SERVER_MESSAGE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
564 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
565 |
flib_log_w("Net: Empty SERVERMESSAGE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
566 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
567 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_SERVERMESSAGE, netmsg->parts[1]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
568 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
569 |
} else if (!strcmp(cmd, "CHAT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
570 |
if(netmsg->partCount < 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
571 |
flib_log_w("Net: Empty CHAT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
572 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
573 |
conn->onChatCb(conn->onChatCtx, netmsg->parts[1], netmsg->parts[2]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
574 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
575 |
} else if (!strcmp(cmd, "INFO")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
576 |
if(netmsg->partCount < 5) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
577 |
flib_log_w("Net: Malformed INFO message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
578 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
579 |
char *joined = flib_join(netmsg->parts+1, netmsg->partCount-1, "\n"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
580 |
if(joined) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
581 |
conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_PLAYERINFO, joined); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
582 |
} |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
583 |
free(joined); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
584 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
585 |
} else if(!strcmp(cmd, "SERVER_VARS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
586 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
587 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
588 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
589 |
// while (tmp.size() >= 2) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
590 |
// { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
591 |
// 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
|
592 |
// 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
|
593 |
// 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
|
594 |
// |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
595 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
596 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
597 |
// } |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
598 |
} else if (!strcmp(cmd, "CLIENT_FLAGS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
599 |
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
|
600 |
flib_log_w("Net: Malformed CLIENT_FLAGS message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
601 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
602 |
const char *flags = netmsg->parts[1]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
603 |
bool setFlag = flags[0] == '+'; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
604 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
605 |
for(int i=1; flags[i]; i++) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
606 |
switch(flags[i]) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
607 |
case 'r': |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
608 |
for(int j = 2; j < netmsg->partCount; ++j) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
609 |
if (!strcmp(conn->playerName, netmsg->parts[i])) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
610 |
// TODO what is the reason behind this (copied from QtFrontend)? |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
611 |
if (conn->isChief && !setFlag) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
612 |
flib_netbase_sendf(conn->netBase, "%s\n\n", "TOGGLE_READY"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
613 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
614 |
} |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
615 |
conn->onReadyStateCb(conn->onReadyStateCtx, netmsg->parts[i], setFlag); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
616 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
617 |
break; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
618 |
default: |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
619 |
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
|
620 |
break; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
621 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
622 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
623 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
624 |
} else if (!strcmp(cmd, "ADD_TEAM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
625 |
if(netmsg->partCount != 24) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
626 |
flib_log_w("Net: Bad ADD_TEAM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
627 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
628 |
flib_team *team = flib_team_from_netmsg(netmsg->parts+1); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
629 |
if(!team) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
630 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
631 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Internal error"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
632 |
exit = true; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
633 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
634 |
conn->onTeamAddCb(conn->onTeamAddCtx, team); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
635 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
636 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
637 |
} else if (!strcmp(cmd, "REMOVE_TEAM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
638 |
if(netmsg->partCount != 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
639 |
flib_log_w("Net: Bad REMOVETEAM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
640 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
641 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
642 |
// emit RemoveNetTeam(HWTeam(lst[1])); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
643 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
644 |
} else if(!strcmp(cmd, "ROOMABANDONED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
645 |
conn->netconnState = NETCONN_STATE_LOBBY; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
646 |
conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_ABANDONED, "Room destroyed"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
647 |
} else if(!strcmp(cmd, "KICKED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
648 |
conn->netconnState = NETCONN_STATE_LOBBY; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
649 |
conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_KICKED, "You got kicked"); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
650 |
} else if(!strcmp(cmd, "JOINED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
651 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
652 |
flib_log_w("Net: Bad JOINED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
653 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
654 |
for(int i = 1; i < netmsg->partCount; ++i) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
655 |
{ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
656 |
bool isMe = !strcmp(conn->playerName, netmsg->parts[i]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
657 |
if (isMe) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
658 |
conn->netconnState = NETCONN_STATE_ROOM; |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
659 |
conn->onEnterRoomCb(conn->onEnterRoomCtx, conn->isChief); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
660 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
661 |
|
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
662 |
conn->onRoomJoinCb(conn->onRoomJoinCtx, netmsg->parts[i]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
663 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
664 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
665 |
} else if(!strcmp(cmd, "LOBBY:JOINED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
666 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
667 |
flib_log_w("Net: Bad JOINED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
668 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
669 |
for(int i = 1; i < netmsg->partCount; ++i) |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
670 |
{ |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
671 |
bool isMe = !strcmp(conn->playerName, netmsg->parts[i]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
672 |
if (isMe) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
673 |
if(flib_netbase_sendf(conn->netBase, "%s\n\n", "LIST")) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
674 |
// If sending this fails, the protocol breaks (we'd be waiting infinitely for the room list) |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
675 |
flib_netbase_sendf(net, "%s\n%s\n\n", "QUIT", "Client error"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
676 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
677 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Failed to send a critical message."); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
678 |
exit = true; |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
679 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
680 |
} |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
681 |
conn->onLobbyJoinCb(conn->onLobbyJoinCtx, netmsg->parts[i]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
682 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
683 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
684 |
} else if(!strcmp(cmd, "LEFT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
685 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
686 |
flib_log_w("Net: Bad LEFT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
687 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
688 |
conn->onRoomLeaveCb(conn->onRoomLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
689 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
690 |
} else if(!strcmp(cmd, "ROOM") && netmsg->partCount >= 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
691 |
const char *subcmd = netmsg->parts[1]; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
692 |
if(!strcmp(subcmd, "ADD") && netmsg->partCount == 10) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
693 |
if(flib_roomlist_add(conn->roomList, netmsg->parts+2)) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
694 |
flib_log_e("Error adding new room to list"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
695 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
696 |
conn->onRoomAddCb(conn->onRoomAddCtx, conn->roomList->rooms[0]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
697 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
698 |
} else if(!strcmp(subcmd, "UPD") && netmsg->partCount == 11) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
699 |
if(flib_roomlist_update(conn->roomList, netmsg->parts[2], netmsg->parts+3)) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
700 |
flib_log_e("Error updating room in list"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
701 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
702 |
conn->onRoomUpdateCb(conn->onRoomUpdateCtx, netmsg->parts[2], flib_roomlist_find(conn->roomList, netmsg->parts[2])); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
703 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
704 |
} else if(!strcmp(subcmd, "DEL") && netmsg->partCount == 3) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
705 |
if(flib_roomlist_delete(conn->roomList, netmsg->parts[2])) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
706 |
flib_log_e("Error deleting room from list"); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
707 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
708 |
conn->onRoomDeleteCb(conn->onRoomDeleteCtx, netmsg->parts[2]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
709 |
} |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
710 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
711 |
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
|
712 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
713 |
} else if(!strcmp(cmd, "LOBBY:LEFT")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
714 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
715 |
flib_log_w("Net: Bad LOBBY:LEFT message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
716 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
717 |
conn->onLobbyLeaveCb(conn->onLobbyLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
718 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
719 |
} else if (!strcmp(cmd, "RUN_GAME")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
720 |
conn->netconnState = NETCONN_STATE_INGAME; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
721 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
722 |
// emit AskForRunGame(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
723 |
} else if (!strcmp(cmd, "ASKPASSWORD")) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
724 |
conn->onPasswordRequestCb(conn->onPasswordRequestCtx, conn->playerName); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
725 |
} else if (!strcmp(cmd, "NOTICE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
726 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
727 |
flib_log_w("Net: Bad NOTICE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
728 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
729 |
errno = 0; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
730 |
long n = strtol(netmsg->parts[1], NULL, 10); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
731 |
if(errno) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
732 |
flib_log_w("Net: Bad NOTICE message"); |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
733 |
} else if(n==0) { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
734 |
conn->onNickTakenCb(conn->onNickTakenCtx, conn->playerName); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
735 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
736 |
flib_log_w("Net: Unknown NOTICE message: %l", n); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
737 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
738 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
739 |
} else if (!strcmp(cmd, "TEAM_ACCEPTED")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
740 |
if (netmsg->partCount != 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
741 |
flib_log_w("Net: Bad TEAM_ACCEPTED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
742 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
743 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
744 |
// emit TeamAccepted(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
745 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
746 |
} else if (!strcmp(cmd, "CFG")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
747 |
if(netmsg->partCount < 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
748 |
flib_log_w("Net: Bad CFG message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
749 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
750 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
751 |
// QStringList tmp = lst; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
752 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
753 |
// tmp.removeFirst(); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
754 |
// if (lst[1] == "SCHEME") |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
755 |
// emit netSchemeConfig(tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
756 |
// else |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
757 |
// emit paramChanged(lst[1], tmp); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
758 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
759 |
} else if (!strcmp(cmd, "HH_NUM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
760 |
if (netmsg->partCount != 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
761 |
flib_log_w("Net: Bad TEAM_ACCEPTED message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
762 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
763 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
764 |
// HWTeam tmptm(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
765 |
// tmptm.setNumHedgehogs(lst[2].toUInt()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
766 |
// emit hhnumChanged(tmptm); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
767 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
768 |
} else if (!strcmp(cmd, "TEAM_COLOR")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
769 |
if (netmsg->partCount != 3) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
770 |
flib_log_w("Net: Bad TEAM_COLOR message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
771 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
772 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
773 |
// HWTeam tmptm(lst[1]); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
774 |
// tmptm.setColor(lst[2].toInt()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
775 |
// emit teamColorChanged(tmptm); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
776 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
777 |
} else if (!strcmp(cmd, "EM")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
778 |
if(netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
779 |
flib_log_w("Net: Bad EM message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
780 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
781 |
// TODO |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
782 |
// for(int i = 1; i < netmsg->partCount; ++i) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
783 |
// QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
784 |
// emit FromNet(em); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
785 |
// } |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
786 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
787 |
} else if (!strcmp(cmd, "BYE")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
788 |
if (netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
789 |
flib_log_w("Net: Bad BYE message"); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
790 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
791 |
conn->netconnState = NETCONN_STATE_DISCONNECTED; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
792 |
if (!strcmp(netmsg->parts[1], "Authentication failed")) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
793 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_AUTH_FAILED, netmsg->parts[1]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
794 |
} else { |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
795 |
conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_NORMAL, netmsg->parts[1]); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
796 |
} |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
797 |
exit = true; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
798 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
799 |
} else if (!strcmp(cmd, "ADMIN_ACCESS")) { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
800 |
// TODO callback? |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
801 |
conn->isAdmin = true; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
802 |
} else if (!strcmp(cmd, "ROOM_CONTROL_ACCESS")) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
803 |
if (netmsg->partCount < 2) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
804 |
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
|
805 |
} else { |
7269
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
806 |
conn->isChief = strcmp("0", netmsg->parts[1]); |
5b0aeef8ba2a
More progress on the netplay part of the frontlib
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
807 |
conn->onRoomChiefStatusCb(conn->onRoomChiefStatusCtx, conn->isChief); |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
808 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
809 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
810 |
flib_log_w("Unknown server command: %s", cmd); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
811 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
812 |
flib_netmsg_destroy(netmsg); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
813 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
814 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
815 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
816 |
void flib_netconn_tick(flib_netconn *conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
817 |
if(!conn) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
818 |
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
|
819 |
} else if(conn->running) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
820 |
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
|
821 |
} else if(conn->netconnState == NETCONN_STATE_DISCONNECTED) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
822 |
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
|
823 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
824 |
conn->running = true; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
825 |
flib_netconn_wrappedtick(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
826 |
conn->running = false; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
827 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
828 |
if(conn->destroyRequested) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
829 |
flib_netconn_destroy(conn); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
830 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
831 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
832 |
} |