Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void packets::msg_login(player *plr)
- {
- mysql_init(&mysql);
- connection = mysql_real_connect(&mysql,"localhost","killerloader","Jellypig1231","crystalonline",0,0,0);
- plr->version = readstring();
- plr->username = readstring();
- if(plr->version!=globals::version)
- {
- server::print("This account has an incorrect version! ["+plr->username+"]", game::c_red);
- }
- else
- {
- plr->password = readstring();
- if(server::method == LOCAL_LOGIN)
- {
- int rownum;
- string query = "SELECT username FROM users WHERE username = '"+plr->username+"'";
- mysql_query(connection, query.c_str());
- result = mysql_store_result(connection);
- if(mysql_num_rows(result)==1)
- {
- int denyammount=0;
- //GREEN ARROW HERE->
- vector <int> denyreason;
- for(unsigned int i=0; i<players::list.size(); i++)
- {
- if(players::list[i]->username == plr->username && players::list[i]->loggedIn)
- {
- denyreason.push_back(2);
- denyammount++;
- server::print("this account is already logged in! ["+plr->username+"]", game::c_red);
- }
- }
- string queryy = "SELECT * FROM users WHERE username = '"+plr->username+"'";
- mysql_query(connection, queryy.c_str());
- result = mysql_store_result(connection);
- row = mysql_fetch_row(result);
- vector <string> rowstring;
- vector <int> rowreal;
- for(int i = 0; i<20; i++)
- rowstring.push_back(row[i]);
- for(int i = 0; i<20; i++)
- rowreal.push_back(atoi(row[i]));
- MYSQL_ROW invrow;
- MYSQL_ROW invsrow;
- queryy = "SELECT * FROM invslots WHERE username = '"+plr->username+"'";
- mysql_query(connection, queryy.c_str());
- result = mysql_store_result(connection);
- invrow = mysql_fetch_row(result);
- for(int i = 1; i<=rowreal[5]; i++)
- plr->invslot.push_back(atoi(invrow[i]));
- queryy = "SELECT * FROM invslotsstack WHERE username = '"+plr->username+"'";
- mysql_query(connection, queryy.c_str());
- result = mysql_store_result(connection);
- invsrow = mysql_fetch_row(result);
- for(int i = 1; i<=rowreal[5]; i++)
- plr->invslotstack.push_back(atoi(invsrow[i]));
- if(rowstring[15]=="1")
- {
- server::print("["+plr->username+"] tried to login to a banned account!", game::c_red);
- denyammount++;
- }
- if(rowstring[1]!=plr->password)
- {
- server::print(row[0]);
- server::print(plr->password.c_str());
- denyreason.push_back(1);
- denyammount++;
- }
- if(denyammount!=0)
- {
- clearbuffer();
- writebyte(5);
- writebyte(denyammount);
- for(int i=0;i<denyammount;i++)
- {
- writebyte(denyreason[i]);
- }
- sendm(plr->socket);
- }
- else
- {
- //row order--
- //--
- //0-username
- //1-password
- //2-x
- //3-y
- //4-rank
- //5-invslots
- //6-currentroom
- //7-belt
- //8-beltslot
- //9-helmet
- //10-helmetslot
- //11-eyes
- //12-hair
- //13-weapon
- //14-weaponslot
- //15-banned
- //16-body
- //17-bodyslot
- //--
- plr->x=rowreal[2];
- plr->y=rowreal[3];
- plr->rank=rowreal[4];
- plr->invslots=rowreal[5];
- plr->world=rowreal[6];
- plr->belt=rowreal[7];
- plr->beltslot=rowreal[8];
- plr->helmet=rowreal[9];
- plr->helmetslot=rowreal[10];
- plr->eyes=rowreal[11];
- plr->hair=rowreal[12];
- server::print(server::doubleToString(plr->hair));
- plr->weapon=rowreal[13];
- plr->weaponslot=rowreal[14];
- plr->body=rowreal[16];
- plr->bodyslot=rowreal[17];
- plr->health=rowreal[18];
- plr->maxhealth=rowreal[19];
- clearbuffer();
- writebyte(MSG_LOGIN);
- writebyte(3);
- writeushort(plr->x);
- writeushort(plr->y);
- writebyte(plr->invslots);
- writebyte(plr->world);
- for(int i=0; i<plr->invslots; i++)
- {
- writebyte(plr->invslot[i]);
- writebyte(plr->invslotstack[i]);
- }
- writebyte(plr->weaponslot);
- writebyte(plr->beltslot);
- writebyte(plr->helmetslot);
- writebyte(plr->bodyslot);
- writebyte(plr->hair);
- writebyte(plr->health);
- writebyte(plr->maxhealth);
- sendm(plr->socket);
- server::print("The account["+plr->username+"] has logged into world["+server::doubleToString(plr->world)+"]", game::c_green);
- plr->oldbelt=plr->belt;
- plr->oldbeltslot=plr->beltslot;
- plr->oldweapon=plr->weapon;
- plr->oldweaponslot=plr->weaponslot;
- plr->oldhelmet=plr->helmet;
- plr->oldhelmetslot=plr->helmetslot;
- plr->oldbody=plr->body;
- plr->oldbodyslot=plr->bodyslot;
- plr->oldinvslots=plr->invslots;
- plr->oldworld=plr->world;
- plr->oldx=plr->x;
- plr->oldy=plr->y;
- plr->oldeyes=plr->eyes;
- plr->oldhair=plr->hair;
- plr->oldrank=plr->rank;
- plr->oldhealth=plr->health;
- plr->oldmaxhealth=plr->maxhealth;
- for(int i=0; i<plr->invslots; i++)
- {
- plr->oldinvslot.push_back(plr->invslot[i]);
- plr->oldinvslotstack.push_back(plr->invslotstack[i]);
- }
- //Send data to other players!
- clearbuffer();
- writebyte(2);
- writebyte(plr->playerID);
- writestring(plr->username);
- writeushort(plr->x);
- writeushort(plr->y);
- writebyte(plr->jumpthru);//HSPEED, COMPLETE THIS AFTER YOU MAKE HSPEED VARIABLE!.
- writeshort(plr->hspeed);//jumpthru, COMPLETE THIS AFTER YOU MAKE Jumpthru VARIABLE!.
- writebyte(plr->weapon);
- writebyte(plr->belt);
- writebyte(plr->helmet);
- writebyte(plr->body);
- writebyte(plr->hair);
- writebyte(plr->health);
- writebyte(plr->maxhealth);
- sendm(0, 3, plr);
- for(unsigned int i=0; i<players::list.size(); i++)
- {
- if(players::list[i]->loggedIn && players::list[i]->playerID != plr->playerID && players::list[i]->world == plr->world)
- {
- clearbuffer();
- writebyte(2);
- writebyte(players::list[i]->playerID);
- writestring(players::list[i]->username);
- writeushort(players::list[i]->x);
- writeushort(players::list[i]->y);
- writeshort(players::list[i]->jumpthru);
- writebyte(players::list[i]->hspeed);
- writebyte(players::list[i]->weapon);
- writebyte(players::list[i]->belt);
- writebyte(players::list[i]->helmet);
- writebyte(players::list[i]->body);
- writebyte(players::list[i]->hair);
- writebyte(players::list[i]->health);
- writebyte(players::list[i]->maxhealth);
- sendm(plr->socket);
- }
- }
- for(unsigned int i=0; i<monsters::list.size(); i++)
- {
- server::print("test:["+server::doubleToString(i)+", "+server::doubleToString(monsters::list.size())+", "+server::doubleToString(globals::spawnerworld[monsters::list[i]->spawnerid])+"]");
- if(globals::spawnerworld[monsters::list[i]->spawnerid] == plr->world)
- {
- clearbuffer();
- writebyte(MSG_MONSTERTHINK);//monster think.
- writebyte(3);//Monster spawn before entry.
- writebyte(monsters::list[i]->spawnerid+1);
- writebyte(globals::spawnermonster[monsters::list[i]->spawnerid]+1);
- writebyte(monsters::list[i]->monsterid);
- writeshort(monsters::list[i]->x);
- sendm(plr->socket);
- }
- }
- clearbuffer();
- writebyte(MSG_CLIENTMESSAGE);
- writestring(server::messageOfTheDay);
- sendm(plr->socket);
- plr->loggedIn = true;
- int usersonline=0;
- for(unsigned int i=0; i<players::list.size(); i++)
- {
- if(players::list[i]->loggedIn)
- {
- usersonline++;
- }
- }
- clearbuffer();
- writebyte(4);
- writeshort(usersonline);
- sendm(plr->socket);
- }
- }
- else
- {
- server::print("This account doesnt exist! ["+plr->username+"]", game::c_red);
- clearbuffer();
- writebyte(5);
- writebyte(1);
- writebyte(1);
- sendm(plr->socket);}//Always close the file
- }
- else
- {
- //Use MySQL to login
- /*
- Write your own SQL queries here to login the user. We recommend
- that you use SHA 512 hashing for maximum password security and
- random SALTs appended to the passwords to prevent rainbow SQL tables
- Please do not forget to set the plr->loggedIn variable to true once
- the login has been fully authenticated!
- */
- //If logged in successfully..
- plr->loggedIn = true;
- }
- }
- mysql_close(connection);
- }
Advertisement
Add Comment
Please, Sign In to add comment