/// <summary> /// To set status bar values like Wz, Exp,Quest Exp , Drop rate /// It will be used by DisplayPing timer to display ping /// </summary> /// <param name="packet">Data packet</param> public static void SetStatusValues(byte[] packet) { var statusPacket = Crypt.Decrypt(packet); string status = Encoding.Default.GetString(statusPacket); int i = 0, j = 0; for (int k = 0; k < 4; k++) { if (k == 0) { i = status.IndexOf('['); j = status.IndexOf(']'); Config.WZ = status.Substring(i + 1, (j - i) - 1).Trim(); } else { i = status.IndexOf('[', i); j = status.IndexOf(']', j); } if (k == 1) { Config.EXP = status.Substring(i + 1, (j - i) - 1).Trim(); } if (k == 2) { Config.QUEST_EXP = status.Substring(i + 1, (j - i) - 1).Trim(); } if (k == 3) { Config.DROP_RATE = status.Substring(i + 1, (j - i) - 1).Trim(); } i++; j++; } }
/// <summary> /// Alter charcter packet received from AccountServer(.acl file) according to 562 client /// </summary> /// <param name="packet">packet data</param> /// <returns>returns 952 bytes packet that contains character info compatible</returns> public static byte[] AlterAccountServerPacket(byte[] packet) { var tempbytes = Crypt.Decrypt(packet); for (int i = 32; i <= 784; i += 188) { tempbytes[i + 3] = tempbytes[i + 2]; tempbytes[i + 2] = tempbytes[i + 1]; tempbytes[i + 1] = Convert.ToByte(1); tempbytes[i] = 0x00; } return(Crypt.Encrypt(tempbytes)); }
/// <summary> /// ZoneServer Data Received methd /// Will be executed when data is received from ZoneServer /// Will split packet and add each packet in list and then send it to client /// </summary> /// <param name="sender">EventDrivenTCPClient object</param> /// <param name="data">byte[] data</param> void ZS_DataReceived(EventDrivenTCPClient sender, object data) { try { var packet = (byte[])Convert.ChangeType(data, typeof(byte[])); //File.WriteAllBytes("OGZS_" + Environment.TickCount + "_" + packet.Length, packet); Application.DoEvents(); var packetList = new List <byte[]>(); Application.DoEvents(); packetList.Clear(); Application.DoEvents(); Packet.SplitPackets(packet, packet.Length, ref packetList); foreach (var t in packetList) { var temp = new byte[4]; Array.Copy(t, 4, temp, 0, 4); var id = Packet.GetClientId(temp); if (player.ContainsKey(id)) { var playerinfo = player[id]; //Below condition is for disconneting client or reconnecting client if (playerinfo.ZoneStatus == Config.AS_ID) { if (t.Length == 952) { Write(playerinfo.Client.TcpClient, Packet.AlterAccountServerPacket(t)); } else { Write(playerinfo.Client.TcpClient, t); } } else { Write(playerinfo.Client.TcpClient, t); //Below condition is for disconneting client or reconnecting client if (t.Length == 12 && t[10] == 0x08 && t[11] == 0x11) { Config.PLAYER_COUNT--; //player count update _Main.Update_Player_Count(); //zonelog update _Main.Update_zonelog("<LC> UID = " + id + " " + playerinfo.Account + " User Left"); playerinfo.Prepared = false; LS.Send(Packet.SendDCToLS(id, playerinfo.Account, Packet.GetTime())); playerinfo.ZoneStatus = -1; ZS.Send(Packet.SendDCToASZS(id)); player.Remove(id); if (clients.Contains(playerinfo.Client)) { lock (clients) { clients.Remove(playerinfo.Client); } } } //Set Character Name else if (t.Length == 39 && t[10] == 0x06 && t[11] == 0x11) { playerinfo.CharName = Packet.GetCharName(Crypt.Decrypt(t), 12); } //Below condition is to reduce chance of other packets come under same conditions else if (t.Length > 18 && t[10] == 0x00 && t[11] == 0x18 && t[12] == 0x74 && t[13] == 0xCE && t[14] == 0xCA && t[15] == 0xE9 && t[16] == 0x87 && t[17] == 0x7F && t[18] == 0xAB) { var tempPacket = t; Packet.SetStatusValues(tempPacket); } } //Zone changed Packet : ZoneStatus Change if (t.Length == 11 && t[8] == 0x01 && t[9] == 0xE1) { //zonelog update _Main.Update_zonelog(playerinfo.Account + " (" + id + ") user zone changed " + playerinfo.ZoneStatus + " -> " + t[10]); playerinfo.ZoneStatus = t[10]; } } } } catch (Exception ZSDataArrival) { Logger.Write(Logger.GetLoggerFileName("ZoneServer"), "ZoneServer DataReceived : " + ZSDataArrival.ToString()); } }