Ejemplo n.º 1
0
 private void tick(object source, EventArgs e)
 {
     try
     {
         if (Constants.Authed)
         {
             hb--;
             if (hb <= 0)
             {
                 hb = bp;
                 HashMap <string, object> sd = new HashMap <string, object>();
                 sd["buildId"] = Constants.build;
                 sd["yek"]     = Constants.ke;
                 BaseSocketPacket packet = new BaseSocketPacket();
                 packet.module = Module.USER;
                 packet.cmd    = Cmd.HEART;
                 packet.value  = sd;
                 this.send(packet);
             }
         }
         foreach (SimpleComand observer in observers.Values)
         {
             observer.update();
         }
     }
     catch { }
 }
Ejemplo n.º 2
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int resp = int.Parse(response["result"].ToString());
                switch (resp)
                {
                case 0:
                    PWAdmin.getInstance().igotResponseFromSave();
                    MessageBox.Show("All data saved successfully!");
                    break;

                case 10000:
                    PWAdmin.getInstance().igotResponseFromSave();
                    MessageBox.Show("XML Error please re-check your xml data!");
                    break;

                case 101:
                    PWAdmin.getInstance().igotResponseFromSave();
                    MessageBox.Show("Game Database Demon refused to save the data!");
                    break;

                default:
                    PWAdmin.getInstance().igotResponseFromSave();
                    MessageBox.Show("XML Error please re-check your xml data!");
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 public void sendNotification(String protocol, BaseSocketPacket data)
 {
     if (classes.ContainsKey(protocol))
     {
         classes[protocol].execute(data);
     }
 }
Ejemplo n.º 4
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int resp = int.Parse(response["result"].ToString());
                switch (resp)
                {
                case 0:
                    PWAdmin.getInstance().updateXmlRoleForm(response);
                    break;

                case 10000:
                    PWAdmin.getInstance().resetallForm(false);
                    MessageBox.Show("Character roleId/userId must be numeric!");
                    break;

                default:
                    PWAdmin.getInstance().resetallForm(false);
                    MessageBox.Show("No character found!");
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = int.Parse(response["result"].ToString());
                if (result == 0)
                {
                    PWDataEditorPaied.PWAdmin.getInstance().unlockMaps("Operation was a success, acquiring new data!", false);
                    BaseSocketPacket         packet = new BaseSocketPacket();
                    HashMap <string, object> sd     = new HashMap <string, object>();
                    packet.module = Module.PWADMIN;
                    packet.cmd    = Cmd.STATUS;
                    sd["maps"]    = PWDataEditorPaied.PWAdmin.server_cache.GetMapsString();
                    packet.value  = sd;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().send(packet);
                    }
                }
                else
                {
                    PWDataEditorPaied.PWAdmin.getInstance().unlockMaps("Operation was a failed, program now ready!");
                }
            }
        }
Ejemplo n.º 6
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int resp = int.Parse(response["result"].ToString());
                switch (resp)
                {
                case 0:
                    PWAdmin.getInstance().unlockGMPANEL();
                    break;

                case 10000:
                    PWAdmin.getInstance().unlockGMPANEL();
                    MessageBox.Show("Character roleId/userId must be numeric!");
                    break;

                default:
                    PWAdmin.getInstance().unlockGMPANEL();
                    MessageBox.Show("Unknown server errror!");
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                Dictionary <string, Dictionary <string, Object> > gmeAccounts = new Dictionary <string, Dictionary <string, Object> >();
                try
                {
                    Dictionary <string, Object> gmsacc = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(response["data"].ToString());
                    foreach (KeyValuePair <string, Object> datax in gmsacc)
                    {
                        Dictionary <string, Object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(datax.Value.ToString());
                        gmeAccounts.Add(datax.Key, dic);
                    }
                }
                catch
                { }
                PWAdmin.getInstance().updateAccountManagment(gmeAccounts);
                if (response.ContainsKey("afected"))
                {
                    MessageBox.Show("Succesfuly changed: " + response["afected"] + " rows.");
                }
                if (response.ContainsKey("ERR"))
                {
                    MessageBox.Show(response["ERR"].ToString());
                }
            }
        }
Ejemplo n.º 8
0
 private void onConnectLoc(IAsyncResult ar)
 {
     try
     {
         Socket client = (Socket)ar.AsyncState;
         client.EndConnect(ar);
         dispatchEvent(2, new BaseSocketEvent(BaseSocketEvent.CONNECT, "Socket connected to :" + client.RemoteEndPoint.ToString()));
         connectDone.Set();
         HashMap <string, object> sd = new HashMap <string, object>();
         sd["buildId"] = Constants.build;
         sd["yek"]     = Constants.ke;
         BaseSocketPacket packet = new BaseSocketPacket();
         packet.module = Module.USER;
         packet.cmd    = Cmd.HEART;
         packet.type   = 3;
         packet.value  = sd;
         this.Send(packet);
         sendDone.WaitOne();
         this.Receive();
         receiveDone.WaitOne();
     }
     catch (Exception e)
     {
         dispatchEvent(0, new BaseSocketEvent(BaseSocketEvent.CLOSE, e.Message.ToString()));
     }
 }
Ejemplo n.º 9
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;


            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    Dictionary <string, Dictionary <string, Object> > gmeAccounts = new Dictionary <string, Dictionary <string, Object> >();
                    try
                    {
                        Dictionary <string, Object> gmsacc = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(response["GMS"].ToString());
                        foreach (KeyValuePair <string, Object> datax in gmsacc)
                        {
                            Dictionary <string, Object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(datax.Value.ToString());
                            gmeAccounts.Add(datax.Key, dic);
                        }
                    }
                    catch
                    { }
                    ProfileView.gmeAccounts = gmeAccounts;
                    ProfileView.instance().unlockProfileView();
                    break;

                default:
                    MessageBox.Show("No permission!");
                    ProfileView.instance().unlockProfileView();
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = int.Parse(response["result"].ToString());
                if (result == 0)
                {
                    Dictionary <string, object> allMapsData = new Dictionary <string, object>();
                    if (response.ContainsKey("data"))
                    {
                        allMapsData = JsonConvert.DeserializeObject <Dictionary <string, object> >(response["data"].ToString());

                        foreach (KeyValuePair <string, object> datax in allMapsData)
                        {
                            int id = 0;
                            Int32.TryParse(datax.Value.ToString(), out id);
                            PWDataEditorPaied.PWAdmin.server_cache.getMapByName(datax.Key).status = id;
                        }
                        PWAdmin.getInstance().update_serverStatus();
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void execute(BaseSocketPacket data)
 {
     Dictionary<string, object> response = (Dictionary<string, object>)data.value;
     if (response.ContainsKey("result"))
     {
         PWAdmin.getInstance().eventReturns(response["result"].ToString());
     }
 }
Ejemplo n.º 12
0
 private void resendMiss()
 {
     for (int i = 0; i < SocketManager.missList.Count; i++)
     {
         BaseSocketPacket bs = SocketManager.missList[i];
         baseSocket.Send(bs);
         missList.Remove(bs);
     }
 }
Ejemplo n.º 13
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int resp = int.Parse(response["result"].ToString());
                switch (resp)
                {
                case 0:
                    Dictionary <string, GmAccount> gmeAccounts = new Dictionary <string, GmAccount>();
                    try
                    {
                        Dictionary <string, object> gmsacc = JsonConvert.DeserializeObject <Dictionary <string, object> >(response["gmsacc"].ToString());
                        foreach (KeyValuePair <string, object> datax in gmsacc)
                        {
                            Dictionary <string, object> gmInfo = JsonConvert.DeserializeObject <Dictionary <string, object> >(datax.Value.ToString());
                            GmAccount gm = new GmAccount();
                            if (gmInfo.ContainsKey("perms"))
                            {
                                String[] perms = JsonConvert.DeserializeObject <String[]>(gmInfo["perms"].ToString());
                                gm.permisions = perms.ToList <String>();
                            }
                            if (gmInfo.ContainsKey("info"))
                            {
                                String[] info = JsonConvert.DeserializeObject <String[]>(gmInfo["info"].ToString());
                                gm.id   = info[0];
                                gm.name = info[1];
                            }
                            gmeAccounts.Add(gm.id, gm);
                        }
                    }
                    catch
                    { }
                    PWAdmin.server_cache.gmeAccounts = gmeAccounts;
                    PWAdmin.getInstance().updateGMScreeen();
                    PWAdmin.getInstance().unlockGMPANEL();
                    break;

                case 10000:
                    PWAdmin.getInstance().unlockGMPANEL();
                    MessageBox.Show("No such Account!");
                    break;

                case 10001:
                    PWAdmin.getInstance().unlockGMPANEL();
                    MessageBox.Show("Role ID or User ID must be numeric!");
                    break;

                default:
                    PWAdmin.getInstance().unlockGMPANEL();
                    MessageBox.Show("Unknown server errror!");
                    break;
                }
            }
        }
Ejemplo n.º 14
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = int.Parse(response["result"].ToString());
                if (result == 0)
                {
                    PWAdmin.getInstance().drawEventTab(response);
                }
            }
        }
Ejemplo n.º 15
0
        public virtual void Send(BaseSocketPacket packet)
        {
            if (!this.connected())
            {
                return;
            }
            try
            {
                ByteArray values = new ByteArray();
                int       sn;
                int       validataNumber;
                ByteArray output;
                long      len;
                values.writeInt(packet.module);
                values.writeInt(packet.cmd);
                if (packet.value != null)
                {
                    values.writeObject(packet.value as HashMap <string, object>);
                }
                ;
                sn = this.getSn();
                //     if (packet.state != -1){
                this._stateList[sn] = packet.state;
                // };
                byte[] value = values.Consume();
                validataNumber = this.fnvHash(value);
                output         = new ByteArray();
                output.writeInt(sn);
                output.writeInt(packet.type);
                output.writeInt(validataNumber);
                output.writeBytes(value);
                len = output.Length();
                byte[]    dass    = output.Consume();
                ByteArray packetx = new ByteArray();
                packetx.writeInt(PACKAGE_HEAD);
                packetx.writeInt((int)len);
                packetx.writeBytes(dass);
                byte[] toSend = packetx.Consume();
                this._socket.BeginSend(toSend, 0, toSend.Length, 0, new AsyncCallback(onSendLoc), this._socket);
#if DEBUG
                Console.WriteLine("Sent:" + toSend.Length + " bytes, Packet:" + ((packet.module + "_") + packet.cmd));
#endif
            }
            catch (Exception e)
            {
                dispatchEvent(0, new BaseSocketEvent(BaseSocketEvent.IO_ERROR, e.Message.ToString()));
            }
        }
Ejemplo n.º 16
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = int.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                case 100:
                    MessageBox.Show("Invalid username. Must be between 4 and 16 alfanum characters.");
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                case 101:
                    MessageBox.Show("Invalid password. Must be between 4 and 19 caseSensitve alfanum + ['#','@'.'!'] characters.");
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                case 102:
                    MessageBox.Show("Invalid encryption.");
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                case 200:
                    if (response.ContainsKey("ERR"))
                    {
                        MessageBox.Show("Sql Exception:" + response["ERR"].ToString());
                    }
                    else
                    {
                        MessageBox.Show("Sql Exception.");
                    }
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                default:
                    PWAdmin.getInstance().updateAccountManagment();
                    break;
                }
            }
        }
Ejemplo n.º 17
0
 public void Send(BaseSocketPacket packet)
 {
     if (baseSocket != null)
     {
         baseSocket.Send(packet);
     }
     else
     {
         if (Constants.drawBack)
         {
             SocketManager.missList.Add(packet);
         }
         Constants.Authed = false;
         if (Iobserver.instance() != null)
         {
             Iobserver.instance().init();
         }
     }
 }
Ejemplo n.º 18
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;


            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    PWAdmin.getInstance().unlockShoutdown("Server will restart in #. Program is now Ready!", true);
                    break;

                default:
                    PWAdmin.getInstance().unlockShoutdown("A Restart is already in progress... Program is now Ready!", false);
                    break;
                }
            }
        }
Ejemplo n.º 19
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;


            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                if (result == 0)
                {
                    if (response.ContainsKey("reset"))
                    {
                        PWAdmin.getInstance().reset_chat_line();
                    }
                    SortedList <int, object> sysInfo = JsonConvert.DeserializeObject <SortedList <int, object> >(response["data"].ToString());
                    foreach (KeyValuePair <int, object> datax in sysInfo)
                    {
                        try
                        {
                            String[]     demonData = JsonConvert.DeserializeObject <String[]>(datax.Value.ToString());
                            MessageClass msgc      = new MessageClass();
                            PWAdmin.chatKey = datax.Key;
                            msgc.to         = demonData[0];
                            msgc.from       = demonData[1];
                            msgc.channel    = demonData[2];
                            msgc.message    = demonData[3];
                            msgc.time       = demonData[4];
                            PWAdmin.getInstance().add_chat_line(PWAdmin.chatKey, msgc);
                        }catch
                        {
                        }
                    }
                    PWAdmin.getInstance().reDrawChat();
                }
            }
        }
Ejemplo n.º 20
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = int.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    if (response.ContainsKey("afected"))
                    {
                        MessageBox.Show("Succesfuly changed: " + response["afected"] + " rows.");
                    }
                    PWAdmin.getInstance().updateAccountManagment();
                    break;

                default:
                    MessageBox.Show("Unable to run the query now. Please try again later!");
                    PWAdmin.getInstance().updateAccountManagment();
                    break;
                }
            }
        }
Ejemplo n.º 21
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;


            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    ProfileView.instance().DologinDone();
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                default:
                    ProfileView.instance().DologinDone();
                    break;
                }
            }
        }
Ejemplo n.º 22
0
 public BaseSocketEvent(String type, String protocol = null, BaseSocketPacket data = null)
 {
     this._protocol = protocol;
     this._data     = data;
     this._type     = type;
 }
Ejemplo n.º 23
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;


            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());

                switch (result)
                {
                case 0:
                    if (response.ContainsKey("id"))
                    {
                        if (result == 0 && !response.ContainsKey("perm"))
                        {
                            ProfileView.instance().progress_bar("Not enough privileges!", 0, 0);
                            MessageBox.Show("Not enough privileges!");
                            Constants.canRecoonect = false;
                            if (Iobserver.instance() != null)
                            {
                                Iobserver.instance().close();
                            }
                            return;
                        }
                        int priv = Int32.Parse(response["perm"].ToString());
                        Constants.permission = priv;
                        if (Iobserver.instance() != null)
                        {
                            Iobserver.instance().registerCMDS(priv);
                        }
                        Dictionary <string, Dictionary <string, Object> > gmeAccounts = new Dictionary <string, Dictionary <string, Object> >();
                        try
                        {
                            Dictionary <string, Object> gmsacc = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(response["GMS"].ToString());
                            foreach (KeyValuePair <string, Object> datax in gmsacc)
                            {
                                Dictionary <string, Object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(datax.Value.ToString());
                                gmeAccounts.Add(datax.Key, dic);
                            }
                        }
                        catch
                        { }
                        ProfileView.gmeAccounts = gmeAccounts;


                        int playerID = Int32.Parse(response["id"].ToString());
                        Constants.Authed = true;
                        Constants.midb   = writeInt(playerID);
                        ProfileView.instance().progress_bar("Connected !", 0, 0);
                        ProfileView.instance().loginDone();
                    }
                    break;

                case 100:
                    // INVALID_STRUCTURE_HWKEY
                    ProfileView.instance().progress_bar("Invalid password!", 0, 0);
                    MessageBox.Show("Invalid password!");
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 101:
                    // INVALID_BUILD
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 102:
                    // INVALID_BUILD
                    ProfileView.instance().progress_bar("Invalid password!", 0, 0);
                    MessageBox.Show("Invalid password!");
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 103:
                    ProfileView.instance().progress_bar("Not enough privileges!", 0, 0);
                    MessageBox.Show("Not enough privileges!");
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 104:
                    ProfileView.instance().progress_bar("Already logged in!", 0, 0);
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    MessageBox.Show("Already logged in!");
                    break;
                }
            }
        }
Ejemplo n.º 24
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    PWAdmin.server_cache.reset();
                    Dictionary <string, object> game = new Dictionary <string, object>();
                    try
                    {
                        game = JsonConvert.DeserializeObject <Dictionary <string, object> > (response["game"].ToString());
                    }
                    catch { }

                    Dictionary <string, object> allMapsData = new Dictionary <string, object>();
                    if (game.ContainsKey("allMaps"))
                    {
                        allMapsData = JsonConvert.DeserializeObject <Dictionary <string, object> >(game["allMaps"].ToString());

                        foreach (KeyValuePair <string, object> datax in allMapsData)
                        {
                            int id = 0;
                            Int32.TryParse(datax.Value.ToString(), out id);
                            PWAdmin.server_cache.getMapByName(datax.Key).status = id;
                        }
                    }

                    Dictionary <string, object> demons_update = new Dictionary <string, object>();
                    if (game.ContainsKey("allDemons"))
                    {
                        demons_update = JsonConvert.DeserializeObject <Dictionary <string, object> >(game["allDemons"].ToString());
                    }

                    foreach (KeyValuePair <string, object> datax in demons_update)
                    {
                        try
                        {
                            String[] demonData = JsonConvert.DeserializeObject <String[]>(datax.ToString());
                            int      idd       = Int32.Parse(demonData[0]);
                            int      status    = Int32.Parse(demonData[1]);
                            PWAdmin.server_cache.updateDemonByID(idd, status);
                        }
                        catch { }
                    }


                    Dictionary <string, object> sysInfo = new Dictionary <string, object>();
                    if (response.ContainsKey("data"))
                    {
                        sysInfo = JsonConvert.DeserializeObject <Dictionary <string, object> >(response["data"].ToString());
                    }

                    foreach (KeyValuePair <string, object> datax in sysInfo)
                    {
                        try
                        {
                            switch (datax.Key)
                            {
                            case "availableProcessors":
                                PWAdmin.server_cache.numCores = datax.Value.ToString();
                                break;

                            case "getSystemCpuLoad":
                                PWAdmin.server_cache.ghzused = datax.Value.ToString();
                                break;
                            }
                        }
                        catch { }
                    }
                    if (game != null)
                    {
                        foreach (KeyValuePair <string, object> datax in game)
                        {
                            try
                            {
                                switch (datax.Key)
                                {
                                case "map_online_count":
                                    PWAdmin.server_cache.map_online_count = datax.Value.ToString();
                                    break;

                                case "totalAcc":
                                    PWAdmin.server_cache.totalAcc = datax.Value.ToString();
                                    break;

                                case "totalOnline":
                                    PWAdmin.server_cache.onlineAcc = datax.Value.ToString();
                                    break;

                                case "mem":
                                    String[] mem = JsonConvert.DeserializeObject <String[]>(datax.Value.ToString());
                                    PWAdmin.server_cache.ramfree  = mem[3];
                                    PWAdmin.server_cache.ramtotal = mem[1];
                                    PWAdmin.server_cache.ramused  = mem[2];
                                    break;

                                case "swp":
                                    String[] swp = JsonConvert.DeserializeObject <String[]>(datax.Value.ToString());
                                    PWAdmin.server_cache.swpfree  = swp[3];
                                    PWAdmin.server_cache.swptotal = swp[1];
                                    PWAdmin.server_cache.swpused  = swp[2];
                                    break;

                                case "CPUmhz":
                                    PWAdmin.server_cache.ghzmax = datax.Value.ToString();
                                    break;
                                }
                            }
                            catch { }
                        }
                    }
                    BaseSocketPacket         packet = new BaseSocketPacket();
                    HashMap <string, object> sd     = new HashMap <string, object>();
                    packet.module = Module.PWADMIN;
                    packet.cmd    = Cmd.ANALLMAPUPDATE;
                    sd["maps"]    = "";
                    packet.value  = sd;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().send(packet);
                    }

                    PWAdmin.getInstance().update_serverStatus();
                    break;
                }
            }
        }
Ejemplo n.º 25
0
        protected void recived(int bytesRead)
        {
            if (!this.connected())
            {
                return;
            }
            try
            {
                int              head   = 0;
                int              len    = 0;
                int              sn     = 0;
                int              type   = 0;
                int              module = 0;
                int              cmd    = 0;
                Double           time   = 0;
                int              status;
                String           protocol = "";
                BaseSocketPacket packet;
                int              recevs = bytesRead;
                int              length = (int)this._totalBytes.Length();
                this._totalBytes.Write(this.carragebytes, length, recevs);
                this.Receive();
#if DEBUG
                Console.WriteLine("Recived:" + bytesRead + " bytes.");
#endif
                ByteArray bytes = new ByteArray();
                while (this._totalBytes.bytesAvailable() >= this.HEADER_LEN)
                {
                    head = this._totalBytes.ReadInt32();
                    while (head != PACKAGE_HEAD)
                    {
                        this._totalBytes.Position(this._totalBytes.Position() - 3);
                        if (this._totalBytes.bytesAvailable() >= this.HEADER_LEN)
                        {
                            head = this._totalBytes.ReadInt32();
                        }
                        else
                        {
                            return;
                        };
                    }
                    ;
                    len = this._totalBytes.ReadInt32();
                    if (this._totalBytes.bytesAvailable() < len)
                    {
                        this._totalBytes.Position(this._totalBytes.Position() - this.HEADER_LEN);
                        return;
                    }
                    bytes.clear();
                    this._totalBytes.readBytes(bytes, 0, len);
                    this._totalBytes.clear();
                    sn       = bytes.ReadInt32();
                    type     = bytes.ReadInt32();
                    module   = bytes.ReadInt32();
                    cmd      = bytes.ReadInt32();
                    time     = bytes.ReadDouble32();
                    status   = bytes.ReadInt32();
                    protocol = ((module + "_") + cmd);
#if DEBUG
                    Console.WriteLine("Read toatal:" + bytes.Length() + " bytes, Packet:" + ((module + "_") + cmd));
#endif
                    switch (status)
                    {
                    case BaseSocketResponseType.RESPONSE_CODE_SUCCESS:
                        if (bytes.bytesAvailable() > 0)
                        {
                            packet        = new BaseSocketPacket();
                            packet.sn     = sn;
                            packet.type   = type;
                            packet.module = module;
                            packet.cmd    = cmd;
                            packet.time   = time;
                            packet.value  = bytes.readObject(type);
                            packet.state  = (sn != -1 || this._stateList.ContainsKey(sn)) ? this._stateList[sn] : 0;
                            dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RECEIVED, protocol, packet));
                            if (this._stateList.ContainsKey(sn))
                            {
                                this._stateList.Remove(sn);
                            }
                        }
                        break;

                    case BaseSocketResponseType.RESPONSE_CODE_NO_RESULTS:
                        dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RESPONSE_CODE_NO_RESULTS, protocol));
                        break;

                    case BaseSocketResponseType.RESPONSE_CODE_RESOLVE_ERROR:
                        dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RESPONSE_CODE_RESOLVE_ERROR, protocol));
                        break;

                    case BaseSocketResponseType.RESPONSE_CODE_NO_RIGHT:
                        dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RESPONSE_CODE_NO_RIGHT, protocol));
                        break;

                    case BaseSocketResponseType.RESPONSE_CODE_AUTH_CODE_ERROR:
                        dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RESPONSE_CODE_AUTH_CODE_ERROR, protocol));
                        break;

                    case BaseSocketResponseType.RESPONSE_CODE_ERROR:
                        dispatchEvent(1, new BaseSocketEvent(BaseSocketEvent.RESPONSE_CODE_ERROR, protocol));
                        break;
                    }
                }
                bytes.clear();
                int bitesav = this._totalBytes.bytesAvailable();
                if (bitesav > 0) // If totalBytes contains bytes avalible
                {
                    this._totalBytes.readBytes(bytes, 0, bitesav);
                }
                ;
                this._totalBytes.clear();
                bitesav = bytes.bytesAvailable();
                if (bitesav > 0)
                {
                    bytes.readBytes(this._totalBytes, 0, bitesav);
                }
                ;
            }
            catch (JsonException)
            {
                PWAdmin.getInstance().resetallForm(false);
                PWAdmin.getInstance().unlockMaps("Ready");
            }
            catch (Exception e)
            {
                dispatchEvent(0, new BaseSocketEvent(BaseSocketEvent.IO_ERROR, e.Message.ToString()));
            }
        }
Ejemplo n.º 26
0
        public void execute(BaseSocketPacket data)
        {
            Dictionary <string, object> response = (Dictionary <string, object>)data.value;

            if (response.ContainsKey("result"))
            {
                int result = Int32.Parse(response["result"].ToString());
                switch (result)
                {
                case 0:
                    if (!Constants.Authed && data.type == 3)
                    {
                        BaseSocketPacket         packet = new BaseSocketPacket();
                        HashMap <string, object> sd     = new HashMap <string, object>();
                        sd["buildId"] = Constants.build;
                        sd["yek"]     = Constants.ke;
                        sd["usr"]     = ProfileView.profile.userName;
                        sd["pwd"]     = ProfileView.profile.passWord;
                        sd["key"]     = ProfileView.profile.keyString;
                        packet.module = Module.USER;
                        packet.cmd    = Cmd.AUTH;
                        packet.value  = sd;
                        ProfileView.instance().progress_bar("Connected !", 0, 0);
                        if (Iobserver.instance() != null)
                        {
                            Iobserver.instance().send(packet);
                        }
                    }

                    if (data.type == 2 && response.ContainsKey("data") && Constants.Authed)
                    {
                        Dictionary <string, object> sysInfo = JsonConvert.DeserializeObject <Dictionary <string, object> >(response["data"].ToString());
                        foreach (KeyValuePair <string, object> datax in sysInfo)
                        {
                            String[]     demonData = JsonConvert.DeserializeObject <String[]>(datax.Value.ToString());
                            MessageClass msgc      = new MessageClass();
                            int          key       = Int32.Parse(datax.Key);
                            msgc.to      = demonData[0];
                            msgc.channel = demonData[2];
                            msgc.from    = demonData[1];

                            msgc.message = demonData[3];
                            msgc.time    = demonData[4];
                            PWAdmin.getInstance().add_chat_line(key, msgc);
                        }
                    }

                    break;

                case 100:
                    // INVALID_STRUCTURE_HWKEY
                    ProfileView.instance().progress_bar("Invalid password!", 0, 0);
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 101:
                    // INVALID_BUILD
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;

                case 102:
                    // INVALID_BUILD
                    ProfileView.instance().progress_bar("Not enough privileges!", 0, 0);
                    Constants.canRecoonect = false;
                    if (Iobserver.instance() != null)
                    {
                        Iobserver.instance().close();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 27
0
 public void send(BaseSocketPacket data)
 {
     this.bs.Send(data);
 }