MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / MPConnection_BeginConnect

Function MPConnection_BeginConnect

src/Server.c:301–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301static void MPConnection_BeginConnect(void) {
302 static const cc_string invalid_reason = String_FromConst("Invalid IP address");
303 cc_string title; char titleBuffer[STRING_SIZE];
304 cc_sockaddr addrs[SOCKET_MAX_ADDRS];
305 int numValidAddrs;
306 cc_result res;
307 String_InitArray(title, titleBuffer);
308
309 /* Default block permissions (in case server supports SetBlockPermissions but doesn't send) */
310 Blocks.CanPlace[BLOCK_AIR] = false;
311 Blocks.CanPlace[BLOCK_LAVA] = false; Blocks.CanDelete[BLOCK_LAVA] = false;
312 Blocks.CanPlace[BLOCK_WATER] = false; Blocks.CanDelete[BLOCK_WATER] = false;
313 Blocks.CanPlace[BLOCK_STILL_LAVA] = false; Blocks.CanDelete[BLOCK_STILL_LAVA] = false;
314 Blocks.CanPlace[BLOCK_STILL_WATER] = false; Blocks.CanDelete[BLOCK_STILL_WATER] = false;
315 Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
316
317 res = Socket_ParseAddress(&Server.Address, Server.Port, addrs, &numValidAddrs);
318 if (res == ERR_INVALID_ARGUMENT) {
319 MPConnection_Fail(&invalid_reason); return;
320 } else if (res) {
321 MPConnection_FailConnect(res); return;
322 }
323
324 res = Socket_Create(&net_socket, &addrs[0], true);
325 if (res) { MPConnection_FailConnect(res); return; }
326 res = Socket_Connect(net_socket, &addrs[0]);
327
328 if (res && res != ReturnCode_SocketInProgess && res != ReturnCode_SocketWouldBlock) {
329 MPConnection_FailConnect(res);
330 } else {
331 Server.Disconnected = false;
332 net_connecting = true;
333 net_connectElapsed = 0;
334
335 String_Format2(&title, "Connecting to %s:%i..", &Server.Address, &Server.Port);
336 LoadingScreen_Show(&title, &String_Empty);
337 }
338}
339
340static void MPConnection_SendBlock(int x, int y, int z, BlockID old, BlockID now) {
341 if (now == BLOCK_AIR) {

Callers

nothing calls this directly

Calls 7

Socket_ParseAddressFunction · 0.85
MPConnection_FailFunction · 0.85
MPConnection_FailConnectFunction · 0.85
String_Format2Function · 0.85
LoadingScreen_ShowFunction · 0.85
Socket_CreateFunction · 0.70
Socket_ConnectFunction · 0.70

Tested by

no test coverage detected