Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New G2O][Shared] packetListener
#2
Good idea, but personally I think that the g2o packages are enough and do not require any improvements, look at the fragment of my code and see that it's enough (I do not want you to treat it as hatred)

Squirrel Script
  1. enum packetList
  2. {
  3.    option_lineChat,
  4.    option_hud,
  5.    option_password,
  6.    option_notifications,
  7.  
  8.    id = 255
  9. };
  10.  
  11. class PlayerOptions
  12. {
  13.    constructor(server){
  14.        SCore = server;
  15.        SPlayer = server.SPlayer;
  16.    }
  17.  
  18.    function changeLine(pid, lines)
  19.    {
  20.        mysql_query(SCore.handler, "UPDATE options SET `chat_lines` = '"+lines+"' WHERE `login` = '"+SPlayer[pid].login+"'");
  21.    }
  22.  
  23.    function changeHud(pid, layout)
  24.    {
  25.        mysql_query(SCore.handler, "UPDATE options SET `hud_layout` = '"+layout+"' WHERE `login` = '"+SPlayer[pid].login+"'");
  26.    }
  27.  
  28.    function changePassword(pid, oldPass, newPass)
  29.    {
  30.        local result = mysql_query(SCore.handler, "SELECT * FROM players WHERE `login` = '"+SPlayer[pid].login+"' AND password = '"+crypt(oldPass)+"'");
  31. if(result)
  32.        {
  33.            local row = mysql_fetch_assoc(result);
  34. if(row)
  35.            {
  36.                mysql_query(SCore.handler, "UPDATE players SET `password` = '"+newPass+"' WHERE `login` = '"+SPlayer[pid].login+"'");
  37.            }
  38.            mysql_free_result(result);
  39.        }
  40.    }
  41.  
  42.    function changeNotifications(pid, notification)
  43.    {
  44.        mysql_query(SCore.handler, "UPDATE options SET `notification` = '"+notification+"' WHERE `login` = '"+SPlayer[pid].login+"'");
  45.    }
  46.  
  47.    function receivedPacket(pid, packet)
  48.    {
  49.        if(packet.readUInt8() == packetList.id)
  50.        {
  51.            switch(packet.readUInt8())
  52.            {
  53.                case packetList.option_lineChat: changeLine(pid, packet.readInt8()); break;
  54.                case packetList.option_hud: changeHud(pid, packet.readInt8()); break;
  55.                case packetList.option_password: changePassword(pid, packet.readString(), packet.readString()); break;
  56.                case packetList.option_notifications: changeNotifications(pid, packet.readBool()); break;
  57.            }
  58.        }
  59.    }
  60.  
  61.    SCore = null;
  62.    SPlayer = null;
  63. }


Reply


Messages In This Thread
[New G2O][Shared] packetListener - by Patrix - 04.06.2018, 20:22
RE: [New G2O][Shared] packetListener - by Tommy - 20.06.2018, 02:39

Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client-Side] bindKey Patrix 6 8,972 14.11.2018, 02:32
Last Post: Patrix
  [New G2O][Shared] Command Handler Patrix 3 6,177 05.09.2018, 15:42
Last Post: Patrix
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 17,497 21.01.2018, 19:59
Last Post: Quarchodron
  [New G2O][Client-Side] Key Combination Patrix 1 3,785 23.12.2017, 13:16
Last Post: Patrix
  [G2O v.0.1.0][Client-Side] Notice Board Quarchodron 0 3,140 27.06.2017, 14:28
Last Post: Quarchodron

Forum Jump:


Users browsing this thread: 1 Guest(s)