Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create Event:
- execute code:
- dllinit(false, true, false);
- readdata();
- listen = tcplisten(port, 99, 1);
- //My stuff
- new_con = -1;
- num_cons = 0;
- connections[0] = -1;
- init_console();
- Step Event:
- execute code:
- new_con = tcpaccept(listen,true);//accept incomming connections
- //first problem this is how you handle new connections
- if (new_con) {//if some1 connected
- connections[num_cons] = new_con;//store his socket
- console_add_line("A user connected. Connection id: " + string(num_cons) + " Socket id: " + string(new_con));
- num_cons += 1;//increase number of connections
- }
- for(i = 0; i < num_cons; i += 1) {//for every connections
- if (connections[i] != -1) {//if its connected
- if (!tcpconnected(connections[i])) {
- connections[i] = -1;
- console_add_line("User disconnected. Connections id: "+ string(i) + " and socket id: " + string(connections[i]))
- continue;
- }//check if still connected
- size = receivemessage(connections[i]);//receive messages
- if (size < 0) continue;//if no message continue
- if (size == 0) {
- connections[i] = -1;
- console_add_line("User disconnected. Connections id: "+ string(i) + " and socket id: " + string(connections[i]))
- continue;
- }//if disconnect message
- console_add_line("Received message from Connections id: "+ string(i) + " and socket id: " + string(connections[i]));
- mid = readbyte();//read message id
- switch(mid) {//handle messages
- case 0: //if we want to register...
- var username, password;
- username = readstring();
- password = readstring();
- if (file_exists(username+".ini")= false) // returns whether sucefull
- {
- ini_open(username+".ini");
- u=ini_write_string("Account Info","Username",string_encrypt(username,7));
- p=ini_write_string("Account Info","Password",string_encrypt(password,7));
- i=ini_read_string("Account Info","Username",string_encrypt(username,7));
- j=ini_read_string("Account Info","Password",string_encrypt(password,7));
- console_add_line(string_decrypt(i,7)+" has connected to the server!");
- ini_close();
- clearbuffer();
- writebyte(0);
- writestring("Your account was sucefully created!");
- sendmessage(new_con);
- }
- if(file_exists(username+".ini")=true)
- {
- clearbuffer();
- writebyte(1);
- writestring("Username that you have choosen, already exists");
- sendmessage(new_con);
- }
- break;
- }
- }
- }
- Draw Event:
- execute code:
- console_draw();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement