Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Check if someone has connected
- Player = tcpaccept(socket,1);
- //If someone has connected, add them to the connection list and initialize them
- if(Player)
- {
- //Add to the list of connections
- ds_list_add(ListPlayers,Player); //Add their socket id
- ds_list_add(ListAddresses,lastip()); //Add their ip address
- ds_list_add(ListNames,""); //Add a blank name
- ds_list_add(ListTimeout,0); //Set a timeout for the new player
- setnagle(Player,false); //Activate nodelay
- }
- //Check all sockets for messages
- Index = 0;
- Message = 0;
- repeat(ds_list_size(ListPlayers))
- {
- pSocket = ds_list_find_value(ListPlayers,Index);
- while(1) //Start infinte loop
- {
- Size = receivemessage(pSocket,0); //Recieve next message
- if Size < 0 break; //Exit loop if no messages
- if Size = 0 {remove(Index); break;} //Remove player from game if no present socket
- ds_list_replace(ListTimeout,Index,current_time); //Reset timeout timer
- Message = readbyte(); //Read message id
- script_execute(ds_list_find_value(ListScripts,Message),Index); //Handle the message
- }
- Timeout = current_time-ds_list_find_value(ListTimeout,Index);
- if Timeout > TimeoutMax break; //Kill player by timeout
- Index += 1; //Move to next socket
- }
Advertisement
Add Comment
Please, Sign In to add comment