131 return sendStr(conn, "ROOM_NAME", roomName); |
131 return sendStr(conn, "ROOM_NAME", roomName); |
132 } |
132 } |
133 |
133 |
134 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) { |
134 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) { |
135 int result = -1; |
135 int result = -1; |
136 if(flib_netconn_is_in_room_context(conn)) { |
136 if(conn->netconnState==NETCONN_STATE_ROOM) { |
137 result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART"); |
137 result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART"); |
138 if(!result) { |
138 if(!result) { |
139 netconn_leaveRoom(conn); |
139 netconn_leaveRoom(conn); |
140 } |
140 } |
141 } |
141 } |
188 } |
188 } |
189 return result; |
189 return result; |
190 } |
190 } |
191 |
191 |
192 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) { |
192 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) { |
193 if(!sendStr(conn, "REMOVE_TEAM", teamname)) { |
193 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
194 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
194 if(team && !team->remoteDriven && !sendStr(conn, "REMOVE_TEAM", teamname)) { |
195 if(team && !team->remoteDriven) { |
195 flib_teamlist_delete(&conn->teamlist, teamname); |
196 flib_teamlist_delete(&conn->teamlist, teamname); |
|
197 } |
|
198 return 0; |
196 return 0; |
199 } |
197 } |
200 return -1; |
198 return -1; |
201 } |
199 } |
202 |
200 |
212 } |
210 } |
213 return result; |
211 return result; |
214 } |
212 } |
215 |
213 |
216 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) { |
214 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) { |
217 if(!log_badargs_if4(conn==NULL, flib_strempty(teamname), hogcount<1, hogcount>HEDGEHOGS_PER_TEAM) |
215 if(!log_badargs_if5(conn==NULL, flib_strempty(teamname), hogcount<1, hogcount>HEDGEHOGS_PER_TEAM, !conn->isChief) |
218 && !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) { |
216 && !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) { |
219 if(conn->isChief) { |
217 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
220 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
218 if(team) { |
221 if(team) { |
219 team->hogsInGame = hogcount; |
222 team->hogsInGame = hogcount; |
|
223 } |
|
224 } |
220 } |
225 return 0; |
221 return 0; |
226 } |
222 } |
227 return -1; |
223 return -1; |
228 } |
224 } |
229 |
225 |
230 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) { |
226 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) { |
231 if(!log_badargs_if2(conn==NULL, flib_strempty(teamname)) |
227 if(!log_badargs_if3(conn==NULL, flib_strempty(teamname), !conn->isChief) |
232 && !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) { |
228 && !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) { |
233 if(conn->isChief) { |
229 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
234 flib_team *team = flib_teamlist_find(&conn->teamlist, teamname); |
230 if(team) { |
235 if(team) { |
231 team->colorIndex = colorIndex; |
236 team->colorIndex = colorIndex; |
|
237 } |
|
238 } |
232 } |
239 return 0; |
233 return 0; |
240 } |
234 } |
241 return -1; |
235 return -1; |
242 } |
236 } |
429 } |
423 } |
430 return result; |
424 return result; |
431 } |
425 } |
432 |
426 |
433 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) { |
427 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) { |
434 if(!sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0)) { |
428 return sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0); |
435 if(conn->netconnState == NETCONN_STATE_INGAME) { |
|
436 conn->netconnState = NETCONN_STATE_ROOM; |
|
437 } |
|
438 return 0; |
|
439 } |
|
440 return -1; |
|
441 } |
429 } |
442 |
430 |
443 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) { |
431 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) { |
444 return sendStr(conn, "BAN", playerName); |
432 return sendStr(conn, "BAN", playerName); |
445 } |
433 } |