Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. Create Event:
  2. execute code:
  3.  
  4. dllinit(false, true, false);
  5. readdata();
  6. listen = tcplisten(port, 99, 1);
  7.  
  8. //My stuff
  9. new_con = -1;
  10. num_cons = 0;
  11. connections[0] = -1;
  12.  
  13. init_console();
  14.  
  15.  
  16.  Step Event:
  17. execute code:
  18.  
  19. new_con = tcpaccept(listen,true);//accept incomming connections
  20.  
  21. //first problem this is how you handle new connections
  22. if (new_con) {//if some1 connected
  23.     connections[num_cons] = new_con;//store his socket
  24.     console_add_line("A user connected. Connection id: " + string(num_cons) + " Socket id: " + string(new_con));
  25.     num_cons += 1;//increase number of connections
  26. }
  27.  
  28. for(i = 0; i < num_cons; i += 1) {//for every connections
  29.     if (connections[i] != -1) {//if its connected
  30.         if (!tcpconnected(connections[i])) {
  31.             connections[i] = -1;
  32.             console_add_line("User disconnected. Connections id: "+ string(i) + " and socket id: " + string(connections[i]))
  33.             continue;
  34.         }//check if still connected
  35.         size = receivemessage(connections[i]);//receive messages
  36.         if (size < 0) continue;//if no message continue
  37.        
  38.         if (size == 0) {
  39.             connections[i] = -1;
  40.             console_add_line("User disconnected. Connections id: "+ string(i) + " and socket id: " + string(connections[i]))
  41.             continue;
  42.         }//if disconnect message
  43.        
  44.         console_add_line("Received message from Connections id: "+ string(i) + " and socket id: " + string(connections[i]));
  45.        
  46.        
  47.         mid = readbyte();//read message id
  48.         switch(mid) {//handle messages
  49.             case 0: //if we want to register...
  50.             var username, password;
  51.             username = readstring();
  52.             password = readstring();
  53.             if (file_exists(username+".ini")= false) // returns whether sucefull
  54.             {
  55.             ini_open(username+".ini");
  56.             u=ini_write_string("Account Info","Username",string_encrypt(username,7));
  57.             p=ini_write_string("Account Info","Password",string_encrypt(password,7));
  58.             i=ini_read_string("Account Info","Username",string_encrypt(username,7));
  59.             j=ini_read_string("Account Info","Password",string_encrypt(password,7));
  60.             console_add_line(string_decrypt(i,7)+" has connected to the server!");
  61.             ini_close();
  62.             clearbuffer();
  63.             writebyte(0);
  64.             writestring("Your account was sucefully created!");
  65.             sendmessage(new_con);
  66.             }
  67.            
  68.             if(file_exists(username+".ini")=true)
  69.             {
  70.             clearbuffer();
  71.             writebyte(1);
  72.             writestring("Username that you have choosen, already exists");
  73.             sendmessage(new_con);
  74.             }
  75.            
  76.             break;
  77.         }
  78.     }
  79. }
  80.  
  81.  
  82. Draw Event:
  83. execute code:
  84.  
  85. console_draw();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement