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(); } } }
public void execute(BaseSocketPacket data) { Dictionary <string, object> response = (Dictionary <string, object>)data.value; int result = Int32.Parse(response["result"].ToString()); if (result == 0) { PWAdmin.getInstance().unlockdemons("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"] = PWAdmin.server_cache.GetMapsString(); packet.value = sd; if (Iobserver.instance() != null) { Iobserver.instance().send(packet); } } else { PWAdmin.getInstance().unlockdemons("Operation was a failed, program now ready!"); } }
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; } } }
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())); } }
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; } } }
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; } } }