Guest User

C++ ONLINE GAME ERROR

a guest
Apr 13th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.94 KB | None | 0 0
  1.  
  2. void packets::msg_login(player *plr)
  3. {
  4.  
  5.     mysql_init(&mysql);
  6.     connection = mysql_real_connect(&mysql,"localhost","killerloader","Jellypig1231","crystalonline",0,0,0);
  7.     plr->version = readstring();
  8.     plr->username = readstring();
  9.     if(plr->version!=globals::version)
  10.     {
  11.         server::print("This account has an incorrect version! ["+plr->username+"]", game::c_red);
  12.     }
  13.     else
  14.     {
  15.     plr->password = readstring();
  16.     if(server::method == LOCAL_LOGIN)
  17.     {
  18.         int rownum;
  19.         string query = "SELECT username FROM users WHERE username = '"+plr->username+"'";
  20.         mysql_query(connection, query.c_str());
  21.         result = mysql_store_result(connection);
  22.         if(mysql_num_rows(result)==1)
  23.             {
  24.             int denyammount=0;
  25. //GREEN ARROW HERE->   
  26.             vector <int> denyreason;
  27.             for(unsigned int i=0; i<players::list.size(); i++)
  28.             {
  29.                 if(players::list[i]->username == plr->username && players::list[i]->loggedIn)
  30.                 {
  31.                     denyreason.push_back(2);
  32.                     denyammount++;
  33.                     server::print("this account is already logged in! ["+plr->username+"]", game::c_red);
  34.                 }
  35.             }
  36.             string queryy = "SELECT * FROM users WHERE username = '"+plr->username+"'";
  37.             mysql_query(connection, queryy.c_str());
  38.             result = mysql_store_result(connection);
  39.             row = mysql_fetch_row(result);
  40.             vector <string> rowstring;
  41.             vector <int> rowreal;
  42.             for(int i = 0; i<20; i++)
  43.                 rowstring.push_back(row[i]);
  44.             for(int i = 0;  i<20; i++)
  45.                 rowreal.push_back(atoi(row[i]));
  46.             MYSQL_ROW invrow;
  47.             MYSQL_ROW invsrow;
  48.             queryy = "SELECT * FROM invslots WHERE username = '"+plr->username+"'";
  49.             mysql_query(connection, queryy.c_str());
  50.             result = mysql_store_result(connection);
  51.             invrow = mysql_fetch_row(result);
  52.             for(int i = 1; i<=rowreal[5]; i++)
  53.                 plr->invslot.push_back(atoi(invrow[i]));
  54.             queryy = "SELECT * FROM invslotsstack WHERE username = '"+plr->username+"'";
  55.             mysql_query(connection, queryy.c_str());
  56.             result = mysql_store_result(connection);
  57.             invsrow = mysql_fetch_row(result);
  58.             for(int i = 1; i<=rowreal[5]; i++)
  59.                 plr->invslotstack.push_back(atoi(invsrow[i]));
  60.             if(rowstring[15]=="1")
  61.             {
  62.                 server::print("["+plr->username+"] tried to login to a banned account!", game::c_red);
  63.                 denyammount++;
  64.             }
  65.             if(rowstring[1]!=plr->password)
  66.             {
  67.                 server::print(row[0]);
  68.                 server::print(plr->password.c_str());
  69.                 denyreason.push_back(1);
  70.                 denyammount++;
  71.             }
  72.             if(denyammount!=0)
  73.             {
  74.                 clearbuffer();
  75.                 writebyte(5);
  76.                 writebyte(denyammount);
  77.                 for(int i=0;i<denyammount;i++)
  78.                 {
  79.                     writebyte(denyreason[i]);
  80.                 }
  81.                 sendm(plr->socket);
  82.             }
  83.             else
  84.             {
  85. //row order--
  86. //--
  87. //0-username
  88. //1-password
  89. //2-x
  90. //3-y
  91. //4-rank
  92. //5-invslots
  93. //6-currentroom
  94. //7-belt
  95. //8-beltslot
  96. //9-helmet
  97. //10-helmetslot
  98. //11-eyes
  99. //12-hair
  100. //13-weapon
  101. //14-weaponslot
  102. //15-banned
  103. //16-body
  104. //17-bodyslot
  105. //--
  106.                 plr->x=rowreal[2];
  107.                 plr->y=rowreal[3];
  108.                 plr->rank=rowreal[4];
  109.                 plr->invslots=rowreal[5];
  110.                 plr->world=rowreal[6];
  111.                 plr->belt=rowreal[7];
  112.                 plr->beltslot=rowreal[8];
  113.                 plr->helmet=rowreal[9];
  114.                 plr->helmetslot=rowreal[10];
  115.                 plr->eyes=rowreal[11];
  116.                 plr->hair=rowreal[12];
  117.                 server::print(server::doubleToString(plr->hair));
  118.                 plr->weapon=rowreal[13];
  119.                 plr->weaponslot=rowreal[14];
  120.                 plr->body=rowreal[16];
  121.                 plr->bodyslot=rowreal[17];
  122.                 plr->health=rowreal[18];
  123.                 plr->maxhealth=rowreal[19];
  124.                 clearbuffer();
  125.                 writebyte(MSG_LOGIN);
  126.                 writebyte(3);
  127.                 writeushort(plr->x);
  128.                 writeushort(plr->y);
  129.                 writebyte(plr->invslots);
  130.                 writebyte(plr->world);
  131.                 for(int i=0; i<plr->invslots; i++)
  132.                 {
  133.                     writebyte(plr->invslot[i]);
  134.                     writebyte(plr->invslotstack[i]);
  135.                 }
  136.                 writebyte(plr->weaponslot);
  137.                 writebyte(plr->beltslot);
  138.                 writebyte(plr->helmetslot);
  139.                 writebyte(plr->bodyslot);
  140.                 writebyte(plr->hair);
  141.                 writebyte(plr->health);
  142.                 writebyte(plr->maxhealth);
  143.                 sendm(plr->socket);
  144.                 server::print("The account["+plr->username+"] has logged into world["+server::doubleToString(plr->world)+"]", game::c_green);
  145.                 plr->oldbelt=plr->belt;
  146.                 plr->oldbeltslot=plr->beltslot;
  147.                 plr->oldweapon=plr->weapon;
  148.                 plr->oldweaponslot=plr->weaponslot;
  149.                 plr->oldhelmet=plr->helmet;
  150.                 plr->oldhelmetslot=plr->helmetslot;
  151.                 plr->oldbody=plr->body;
  152.                 plr->oldbodyslot=plr->bodyslot;
  153.                 plr->oldinvslots=plr->invslots;
  154.                 plr->oldworld=plr->world;
  155.                 plr->oldx=plr->x;
  156.                 plr->oldy=plr->y;
  157.                 plr->oldeyes=plr->eyes;
  158.                 plr->oldhair=plr->hair;
  159.                 plr->oldrank=plr->rank;
  160.                 plr->oldhealth=plr->health;
  161.                 plr->oldmaxhealth=plr->maxhealth;
  162.                 for(int i=0; i<plr->invslots; i++)
  163.                 {
  164.                     plr->oldinvslot.push_back(plr->invslot[i]);
  165.                     plr->oldinvslotstack.push_back(plr->invslotstack[i]);
  166.                 }
  167.                 //Send data to other players!
  168.                 clearbuffer();
  169.                 writebyte(2);
  170.                 writebyte(plr->playerID);
  171.                 writestring(plr->username);
  172.                 writeushort(plr->x);
  173.                 writeushort(plr->y);
  174.                 writebyte(plr->jumpthru);//HSPEED, COMPLETE THIS AFTER YOU MAKE HSPEED VARIABLE!.
  175.                 writeshort(plr->hspeed);//jumpthru, COMPLETE THIS AFTER YOU MAKE Jumpthru VARIABLE!.
  176.                 writebyte(plr->weapon);
  177.                 writebyte(plr->belt);
  178.                 writebyte(plr->helmet);
  179.                 writebyte(plr->body);
  180.                 writebyte(plr->hair);
  181.                 writebyte(plr->health);
  182.                 writebyte(plr->maxhealth);
  183.                 sendm(0, 3, plr);
  184.                 for(unsigned int i=0; i<players::list.size(); i++)
  185.                 {
  186.                     if(players::list[i]->loggedIn && players::list[i]->playerID != plr->playerID && players::list[i]->world == plr->world)
  187.                     {
  188.                         clearbuffer();
  189.                         writebyte(2);
  190.                         writebyte(players::list[i]->playerID);
  191.                         writestring(players::list[i]->username);
  192.                         writeushort(players::list[i]->x);
  193.                         writeushort(players::list[i]->y);
  194.                         writeshort(players::list[i]->jumpthru);
  195.                         writebyte(players::list[i]->hspeed);
  196.                         writebyte(players::list[i]->weapon);
  197.                         writebyte(players::list[i]->belt);
  198.                         writebyte(players::list[i]->helmet);
  199.                         writebyte(players::list[i]->body);
  200.                         writebyte(players::list[i]->hair);
  201.                         writebyte(players::list[i]->health);
  202.                         writebyte(players::list[i]->maxhealth);
  203.                         sendm(plr->socket);
  204.                     }
  205.                 }
  206.                 for(unsigned int i=0; i<monsters::list.size(); i++)
  207.                 {
  208.                     server::print("test:["+server::doubleToString(i)+", "+server::doubleToString(monsters::list.size())+", "+server::doubleToString(globals::spawnerworld[monsters::list[i]->spawnerid])+"]");
  209.                     if(globals::spawnerworld[monsters::list[i]->spawnerid] == plr->world)
  210.                     {
  211.                         clearbuffer();
  212.                         writebyte(MSG_MONSTERTHINK);//monster think.
  213.                         writebyte(3);//Monster spawn before entry.
  214.                         writebyte(monsters::list[i]->spawnerid+1);
  215.                         writebyte(globals::spawnermonster[monsters::list[i]->spawnerid]+1);
  216.                         writebyte(monsters::list[i]->monsterid);
  217.                         writeshort(monsters::list[i]->x);
  218.                         sendm(plr->socket);
  219.                     }
  220.                 }
  221.                 clearbuffer();
  222.                 writebyte(MSG_CLIENTMESSAGE);
  223.                 writestring(server::messageOfTheDay);
  224.                 sendm(plr->socket);
  225.                 plr->loggedIn = true;
  226.                 int usersonline=0;
  227.                 for(unsigned int i=0; i<players::list.size(); i++)
  228.                 {
  229.                     if(players::list[i]->loggedIn)
  230.                     {
  231.                         usersonline++;
  232.                     }
  233.                 }
  234.                 clearbuffer();
  235.                 writebyte(4);
  236.                 writeshort(usersonline);
  237.                 sendm(plr->socket);
  238.             }
  239.        
  240.         }  
  241.         else
  242.         {
  243.             server::print("This account doesnt exist! ["+plr->username+"]", game::c_red);
  244.             clearbuffer();
  245.             writebyte(5);
  246.             writebyte(1);
  247.             writebyte(1);
  248.             sendm(plr->socket);}//Always close the file
  249.     }
  250.     else
  251.     {
  252.         //Use MySQL to login
  253.        
  254.         /*
  255.             Write your own SQL queries here to login the user. We recommend
  256.             that you use SHA 512 hashing for maximum password security and
  257.             random SALTs appended to the passwords to prevent rainbow SQL tables
  258.  
  259.             Please do not forget to set the plr->loggedIn variable to true once
  260.             the login has been fully authenticated!
  261.         */
  262.  
  263.         //If logged in successfully..
  264.         plr->loggedIn = true;
  265.     }
  266.     }
  267.     mysql_close(connection);
  268. }
Advertisement
Add Comment
Please, Sign In to add comment