MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AskToJoin

Function AskToJoin

Descent3/multi_connect.cpp:294–327  ·  view source on GitHub ↗

Returns true if the server says we can join

Source from the content-addressed store, hash-verified

292
293// Returns true if the server says we can join
294int AskToJoin(network_address *addr) {
295 int count = 0;
296 int size;
297 int tries = 0;
298 uint8_t data[MAX_GAME_DATA_SIZE];
299 float start_time;
300 network_address from_addr;
301
302 size = START_DATA(MP_ASK_TO_JOIN, data, &count);
303 END_DATA(count, data, size);
304
305 Ok_to_join = -1;
306
307 while (tries < 5 && Ok_to_join == -1) {
308 // Send of our question and then wait!
309 ASSERT(size > 0);
310 nw_Send(addr, data, count, 0);
311 tries++;
312
313 start_time = timer_GetTime();
314 while ((timer_GetTime() - start_time < ASK_POLL_TIME) && Ok_to_join == -1) {
315 int packsize;
316 while (((packsize = nw_Receive(Multi_receive_buffer, &from_addr)) > 0) && Ok_to_join == -1) {
317 MultiProcessBigData(Multi_receive_buffer, packsize, &from_addr);
318 }
319 }
320 }
321
322 if (tries >= 5 || Ok_to_join != JOIN_ANSWER_OK)
323 return 0;
324
325 // Ok to join!
326 return 1;
327}
328
329// Trys to join this client with the server address passed in
330// Returns 1 on success, 0 on fail

Callers 1

TryToJoinServerFunction · 0.85

Calls 5

START_DATAFunction · 0.85
END_DATAFunction · 0.85
nw_SendFunction · 0.85
nw_ReceiveFunction · 0.85
MultiProcessBigDataFunction · 0.85

Tested by

no test coverage detected