public void Wall(string msg) { ByteArrayBuilder pack = new ByteArrayBuilder(false); pack.Add((byte)CHAT.SYSTEM) .Add((uint)0, 0, 0, 0); pack.Add(msg); pack.Add((byte)0); pack.Set(13, (ushort)(pack.Length - 18)); foreach (Character c in GetOnline()) { c.Send(OP.SMSG_MESSAGECHAT, pack); } }
byte[] GetItemsSaveData() { ByteArrayBuilder pack = new ByteArrayBuilder(); for (int i = 0; i < items.Length; i++) { if (items[i] == null) { continue; } pack.Add((byte)i).Add(items[i].Entry); int pos = pack.Length; pack.Add((ushort)0); pack.Add(items[i].GetSaveData()); pack.Set(pos, (ushort)(pack.Length - pos - 2)); } return(pack); }
public override byte[] GetSaveData() { ByteArrayBuilder pack = new ByteArrayBuilder(); pack.Add(base.GetSaveData()); for (int i = 0; i < items.Length; i++) { if (items[i] == null) { continue; } pack.Add((byte)i); pack.Add(items[i].Entry); int pos = pack.Length; pack.Add((ushort)0); pack.Add(items[i].GetSaveData()); pack.Set(pos, (ushort)(pack.Length - pos - 2)); } pack.Add((byte)SlotID.CHARACTER); return(pack); }
public override byte[] OnRecv(byte[] section, int length) { int t; byte[] data; for (int i = 0; i < length; i++) { input.Add(section[i]); } RealmType code = (RealmType)input[0]; switch (code) { case RealmType.LOGON_CHALLENGE: // Logon challenge case RealmType.RECONNECT_CHALLENGE: { if (input.Length < 34 || input.Length < 34 + input[33]) { return(null); } int clientVersion = input.Seek(11).GetWord(); //byte[] blu = input.GetArray(5, input[33]); //Console.WriteLine("DEBUG:" + clientVersion); userName = input.GetArray(34, input[33]); data = input; input.Length = 0; sUserName = System.Text.Encoding.ASCII.GetString(userName); //string ble = System.Text.Encoding.ASCII.GetString(blu); byte [] hash = rl.GetUserPasswordHash(sUserName); //Console.WriteLine("DEBUG - ble:" + ble + "user: "******" code: " + code); } ByteArrayBuilder p = new ByteArrayBuilder(); p.Add((byte)1, 3); p.Add(new byte[116]); return(p); } if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } byte [] res = new Byte[hash.Length + salt.Length]; Const.rand.NextBytes(salt); #if CHECK salt = new byte[] { 0x33, 0xf1, 0x40, 0xd4, 0x6c, 0xb6, 0x6e, 0x63, 0x1f, 0xdb, 0xbb, 0xc9, 0xf0, 0x29, 0xad, 0x88, 0x98, 0xe0, 0x5e, 0xe5, 0x33, 0x87, 0x61, 0x18, 0x18, 0x5e, 0x56, 0xdd, 0xe8, 0x43, 0x67, 0x4f }; #endif t = 0; foreach (byte s in salt) { res[t++] = s; } foreach (byte s in hash) { res[t++] = s; } SHA1 sha = new SHA1CryptoServiceProvider(); byte [] hash2 = sha.ComputeHash(res, 0, res.Length); byte [] x = Reverse(hash2); rN = Reverse(N); Const.rand.NextBytes(b); #if CHECK b = new byte[] { 0x86, 0x92, 0xE3, 0xA6, 0xBA, 0x48, 0xB5, 0xB1, 0x00, 0x4C, 0xEF, 0x76, 0x82, 0x51, 0x27, 0xB7, 0xEB, 0x7D, 0x1A, 0xEF }; #endif rb = Reverse(b); BigInteger bi = new BigInteger(x); BigInteger bi2 = new BigInteger(rN); G = new BigInteger(new byte[] { 7 }); v = G.modPow(bi, bi2); K = new BigInteger(new Byte[] { 3 }); BigInteger temp1 = K * v; BigInteger temp2 = G.modPow(new BigInteger(rb), new BigInteger(rN)); BigInteger temp3 = temp1 + temp2; B = temp3 % new BigInteger(rN); ByteArrayBuilder pack = new ByteArrayBuilder(); pack.Add((byte)0, 0, 0); pack.Add(Reverse(B.getBytes(32))); pack.Add((byte)1, 7, 32); pack.Add(N); pack.Add(salt); pack.Add(new byte[16]); return(pack); } case RealmType.LOGON_PROOF: // Logon proof case RealmType.RECONNECT_PROOF: { if (input.Length < 53) { return(null); } byte[] A = input.GetArray(1, 32); byte[] kM1 = input.GetArray(33, 20); data = input; input.Length = 0; #if CHECK A = new byte[] { 0x23, 0x2f, 0xb1, 0xb8, 0x85, 0x29, 0x64, 0x3d, 0x95, 0xb8, 0xdc, 0xe7, 0x8f, 0x27, 0x50, 0xc7, 0x5b, 0x2d, 0xf3, 0x7a, 0xcb, 0xa8, 0x73, 0xeb, 0x31, 0x07, 0x38, 0x39, 0xed, 0xa0, 0x73, 0x8d }; #endif byte [] rA = Reverse(A); byte [] AB = Concat(A, Reverse(B.getBytes(32))); SHA1 shaM1 = new SHA1CryptoServiceProvider(); byte [] U = shaM1.ComputeHash(AB); byte [] rU = Reverse(U); // SS_Hash BigInteger temp1 = v.modPow(new BigInteger(rU), new BigInteger(rN)); BigInteger temp2 = temp1 * new BigInteger(rA); BigInteger temp3 = temp2.modPow(new BigInteger(rb), new BigInteger(rN)); byte [] S1 = new byte[16]; byte [] S2 = new byte[16]; byte [] S = temp3.getBytes(32); byte [] rS = Reverse(S); for (t = 0; t < 16; t++) { S1[t] = rS[t * 2]; S2[t] = rS[(t * 2) + 1]; } byte [] hashS1 = shaM1.ComputeHash(S1); byte [] hashS2 = shaM1.ComputeHash(S2); byte [] SS_Hash = new byte[hashS1.Length + hashS2.Length]; for (t = 0; t < hashS1.Length; t++) { SS_Hash[t * 2] = hashS1[t]; SS_Hash[(t * 2) + 1] = hashS2[t]; } // cal M1 byte [] NHash = shaM1.ComputeHash(N); byte [] GHash = shaM1.ComputeHash(G.getBytes()); byte [] userHash = shaM1.ComputeHash(userName); byte [] NG_Hash = new byte[20]; for (t = 0; t < 20; t++) { NG_Hash[t] = (byte)(NHash[t] ^ GHash[t]); } byte [] Temp = Concat(NG_Hash, userHash); Temp = Concat(Temp, salt); Temp = Concat(Temp, A); Temp = Concat(Temp, Reverse(B.getBytes(32))); Temp = Concat(Temp, SS_Hash); byte [] M1 = shaM1.ComputeHash(Temp); ByteArrayBuilder pack; if (!ByteArray.Same(M1, kM1)) { if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } pack = new ByteArrayBuilder(); pack.Add((byte)1, 3); pack.Add(new byte[24]); return(pack); } if (LogMessageEvent != null) { LogMessageEvent(sUserName + " code: " + code); } rl.SetUserSessionKey(sUserName, SS_Hash); // cal M2 Temp = Concat(A, M1); Temp = Concat(Temp, SS_Hash); byte [] M2 = shaM1.ComputeHash(Temp); pack = new ByteArrayBuilder(); pack.Add((byte)1, 0); pack.Add(M2); pack.Add(new byte[4]); return(pack); } case RealmType.UPDATESRV: // Update server if (input.Length < 1) { return(null); } data = input; input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("UPDATESRV"); } break; case RealmType.REALMLIST: // Realm List { if (input.Length < 1) { return(null); } byte[] request = input.GetArray(1, 4); input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("REALMLIST"); } ByteArrayBuilder pack = new ByteArrayBuilder(false); pack.Add((byte)RealmType.REALMLIST, 0, 0); pack.Add(request); rl.GetRealmList(sUserName, pack); pack.Add((byte)0, (byte)0); pack.Set(1, (ushort)(pack.Length - 3)); return(pack); } default: data = input; input.Length = 0; if (LogMessageEvent != null) { LogMessageEvent("Receive unknown command {0}" + data[0]); } break; } byte [] ret = { 0, 0 }; return(ret); }
public void SendUpdate(bool bBuild) { if (bBuild) { BuildUpdateForSet(); } if (updatePacket.Count == 0) { return; } ByteArrayBuilder pack = new ByteArrayBuilder(false); pack.Add(new byte[5]); int cnt = 0; foreach (byte[] b in updatePacket) { pack.Add(b); cnt++; if (pack.Length > 32000) { break; } } updatePacket.RemoveRange(0, cnt); pack.Set(0, (ushort)cnt); byte[] data = pack; if (data.Length > 400) // need compress? { /*/ ICSharpCode.SharpZipLib.Zip.Compression.Deflater deflater = new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(); * deflater.SetInput(data); * deflater.Finish(); * * byte[] cdata = new byte[data.Length]; * int len = deflater.Deflate(cdata); * * Console.WriteLine(len); * Console.WriteLine(data.Length); * pack.Length = 0; * // pack = new ByteArrayBuilder(false); * pack.Add((uint)data.Length / 8); * for (int i = 0; i < len; i++) * pack.Add(cdata[i]); * Console.WriteLine(pack.Length); */ // Well, it works.... :-) byte[] temp = { 163, 4, 0, 0, 120, 156, 99, 99, 0, 2, 38, 38, 32, 193, 8, 197, 120, 128, 130, 3, 3, 195, 3, 7, 16, 93, 36, 51, 29, 72, 55, 56, 220, 225, 247, 116, 96, 192, 162, 145, 233, 190, 63, 148, 1, 149, 100, 6, 98, 46, 176, 72, 131, 61, 55, 84, 17, 55, 154, 38, 144, 58, 38, 102, 154, 57, 5, 102, 50, 51, 220, 106, 2, 78, 97, 161, 153, 83, 96, 38, 131, 156, 194, 67, 140, 83, 96, 12, 234, 59, 5, 38, 201, 12, 87, 68, 192, 41, 48, 103, 80, 223, 41, 48, 83, 65, 78, 97, 34, 198, 41, 48, 65, 22, 152, 232, 5, 9, 238, 99, 167, 140, 12, 14, 31, 82, 95, 236, 116, 212, 203, 213, 1, 159, 83, 176, 249, 65, 81, 158, 193, 57, 80, 198, 1, 33, 112, 99, 62, 195, 207, 253, 12, 15, 56, 17, 34, 28, 12, 12, 14, 13, 48, 78, 3, 216, 4, 30, 126, 6, 27, 20, 99, 14, 48, 144, 8, 64, 62, 102, 248, 3, 229, 192, 124, 37, 9, 151, 110, 176, 135, 177, 108, 208, 104, 120, 100, 0, 1, 136, 159, 195, 14, 193, 198, 198, 198, 64, 61, 11, 236, 141, 128, 98, 70, 8, 123, 28, 64, 158, 135, 113, 196, 129, 88, 4,136, 197, 160, 180, 8, 204, 33, 88, 0, 114, 240, 51, 50, 176, 179, 2, 9, 102, 193, 111, 79, 153, 184, 160, 114, 60, 12, 136, 132, 138, 156, 229, 65, 52, 44, 177, 163, 184, 23, 202, 127, 129, 100, 97, 10, 14, 187, 1, 224, 91, 68, 126 }; pack = new ByteArrayBuilder(); pack.Add(temp); Send(OP.SMSG_COMPRESSED_UPDATE_OBJECT, pack); } else { Send(OP.SMSG_UPDATE_OBJECT, data); } }