Ember

SocketAccept

Oct 13th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--Accept incoming connections--//
  2. Incoming = socket_accept(Socket);
  3. if(Incoming)
  4. {
  5.     //Set up incoming connection
  6.     ID = NewPlayerID();
  7.     if(ID)
  8.     {
  9.         with(instance_create(0, 0, Player))
  10.         {
  11.             //This is basically the create event for the player object
  12.             ID = other.ID;
  13.             Socket = other.Incoming;
  14.             SetPlayerID(ID, Socket);
  15.             socket_sendbuffer_limit(Socket, 65535);
  16.             //Send the new player to everyone else
  17.             Buffer = buffer_create();
  18.             buffer_clear(Buffer);
  19.             write_ubyte(Buffer, 0);
  20.             write_ubyte(Buffer, ID);
  21.             write_ubyte(Buffer, 1);
  22.             write_string(Buffer, "E");
  23.             socket_send_all(Buffer, Socket);
  24.             Name = "Unnamed";
  25.             Timeout = 0;
  26.             TimeDelta = current_time;
  27.             Input = 0;
  28.             Players += 1;
  29.         }
  30.         //Send all existing players to new one
  31.         with(Player)
  32.         {
  33.             if(ID != other.ID)
  34.             {
  35.                 write_ubyte(other.Incoming, 0);
  36.                 write_ubyte(other.Incoming, ID);
  37.                 write_ubyte(other.Incoming, Length);
  38.                 write_string(other.Incoming, Name);
  39.                 socket_send(other.Incoming);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment