Ember

Server

Feb 11th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Check if someone has connected
  2. Player = tcpaccept(socket,1);
  3.  
  4. //If someone has connected, add them to the connection list and initialize them
  5. if(Player)
  6. {
  7.     //Add to the list of connections
  8.     ds_list_add(ListPlayers,Player);     //Add their socket id
  9.     ds_list_add(ListAddresses,lastip()); //Add their ip address
  10.     ds_list_add(ListNames,"");           //Add a blank name
  11.     ds_list_add(ListTimeout,0);          //Set a timeout for the new player
  12.     setnagle(Player,false);              //Activate nodelay
  13. }
  14.  
  15. //Check all sockets for messages
  16. Index = 0;
  17. Message = 0;
  18. repeat(ds_list_size(ListPlayers))
  19. {
  20.     pSocket = ds_list_find_value(ListPlayers,Index);
  21.     while(1) //Start infinte loop
  22.     {
  23.         Size = receivemessage(pSocket,0);                              //Recieve next message
  24.         if Size < 0 break;                                             //Exit loop if no messages
  25.         if Size = 0 {remove(Index); break;}                            //Remove player from game if no present socket
  26.         ds_list_replace(ListTimeout,Index,current_time);               //Reset timeout timer
  27.         Message = readbyte();                                          //Read message id
  28.         script_execute(ds_list_find_value(ListScripts,Message),Index); //Handle the message
  29.     }
  30.     Timeout = current_time-ds_list_find_value(ListTimeout,Index);
  31.     if Timeout > TimeoutMax break; //Kill player by timeout
  32.     Index += 1; //Move to next socket
  33. }
Advertisement
Add Comment
Please, Sign In to add comment