public override void OnConnect(ServerSocket parent = null) { if (ClientConnection.CurrentSession == null) throw new Exception("Realm connection with no session"); var realmparent = parent as RealmClientSocket; if (realmparent == null) throw new Exception("Realm connection with non realm parent!"); ClientConnection.CurrentSession.SetRealmInfo(realmparent.GetRealmSettings()); Random rnd = new Random(); Seed = (UInt32) rnd.Next(); PacketOut p = new PacketOut(RealmOp.SMSG_AUTH_CHALLENGE); p.Write((int) 1); p.Write(Seed); p.Write(0xF3539DA3); p.Write(0x6E8547B9); p.Write(0x9A6AA2F8); p.Write(0xA4F170F4); p.Write(0xF3539DA3); p.Write(0x6E8547B9); p.Write(0x9A6AA2F8); p.Write(0xA4F170F4); SendPacket(p); }
public static PacketProcessResult HandlePing(PacketProcessor p) { CMSG_PING pkt = new CMSG_PING(); pkt.Read(p.CurrentPacket); PacketOut pout = new PacketOut(RealmOp.SMSG_PONG); pout.Write(pkt.ping); pout.Finalise(); p.ClientConnection.Send(pout.strm.ToArray()); return PacketProcessResult.Processed; }
public async Task OnLogonChallenge(AuthLogonChallenge challenge) { Account = GrainFactory.GetGrain<IAccount>(challenge.account); if (!(await Account.IsValid())) { await SendAuthError(AuthError.NoAccount); return; } string password = await Account.GetPassword(); Shared.BigInteger pass = new Shared.BigInteger(password, 16); //test string passwordPlain = await Account.GetPasswordPlain(); string SRPHash = challenge.account.ToUpper() + ":" + passwordPlain.ToUpper(); var SRPHashBytes = Encoding.UTF8.GetBytes(SRPHash); var SRPCreds = BigInt.Hash(SRPHashBytes); //The bytes were g BigInteger x = BigInt.Hash(s, SRPCreds); v = g.ModPow(x, N); b = new Shared.BigInteger(new Random(), 160); Shared.BigInteger gmod = g.ModPow(b, N); if (gmod < 0) gmod += N; B = ((v*3) + gmod)%N; if (B < 0) B += N; Shared.BigInteger unk = new Shared.BigInteger(new Random(), 128); //I'm sure this is used for matrix proofing (2 factor auth) PacketOut rtn = new PacketOut(AuthOp.AUTH_LOGON_CHALLENGE); rtn.Write((byte) AuthError.Success); rtn.Write((byte) 0); //unknown rtn.WriteBigInt(B, 32); rtn.WriteBigIntLength(g, 1); rtn.WriteBigIntLength(N, 32); rtn.WriteBigInt(s, 32); rtn.WriteBigInt(unk, 16); rtn.Write((byte) 0); //security flag await SendPacket(rtn); //test }
public async Task HandleNameQuery(CMSG_NAME_QUERY pkt) { var player = GrainFactory.GetGrain<IPlayer>(pkt.guid.ToInt64()); var valid = await player.IsValid(); var guid_packed = new PackedGUID(pkt.guid); PacketOut p = new PacketOut(RealmOp.SMSG_NAME_QUERY_RESPONSE); p.Write(guid_packed); if (!valid) { p.Write((byte)1); //unknown await SendPacket(p); return; } p.Write((byte)0); //known p.WriteCString(await player.GetName()); var realmid = await player.GetRealmID(); if (realmid != await GetRealmID()) //player is on a different realm to this session, append their realm name { var realm_manager = GrainFactory.GetGrain<IRealmManager>(0); p.WriteCString(await realm_manager.GetRealmName((int)realmid)); } else p.Write((byte)0); //null string aka same realm aka dont show anything extra p.Write(await player.GetRace()); p.Write(await player.GetGender()); p.Write(await player.GetClass()); p.Write((byte)0); //isNameDeclined await SendPacket(p); }
public void SendPacket(PacketOut p) { p.Finalise(); var parray = p.strm.ToArray(); ClientConnection.Send(parray, parray.Length); }
public void Write(PacketOut p) { Write(p.strm.ToArray()); }
public async Task OnLogonProof(AuthLogonProof proof) { BigInteger A = new BigInteger(proof.A); BigInteger M1 = new BigInteger(proof.M1); if (A == 0 || M1 == 0) //possible hack attempt { await SendAuthError(AuthError.NoAccount); return; } BigInteger u = BigInt.Hash(A, B); BigInteger tmp = v.ModPow(u, N); if (tmp < 0) tmp += N; BigInteger S = A * tmp; S = S.ModPow(b, N); if (S < 0) S += N; byte[] t = S.GetBytes(); //byte[] t = new byte[32]; byte[] t1 = new byte[16]; byte[] t2 = new byte[16]; byte[] vK = new byte[40]; for (int i = 0; i < 16; ++i) { t1[i] = t[i * 2]; t2[i] = t[(i * 2) + 1]; } var t1sha = BigInt.Hash(t1); var t2sha = BigInt.Hash(t2); var t1shabytes = t1sha.GetBytes(20); var t2shabytes = t2sha.GetBytes(20); for (int i = 0; i < 20; ++i) { vK[i * 2] = t1shabytes[i]; vK[(i * 2) + 1] = t2shabytes[i]; } var t3 = BigInt.Hash(N) ^ BigInt.Hash(g); var AccountName = Account.GetPrimaryKeyString().ToUpper(); var t4bytes = Encoding.UTF8.GetBytes(AccountName); var t4 = BigInt.Hash(t4bytes); t4bytes = t4.GetBytes(); SessionKey = new BigInteger(vK); var M = BigInt.Hash(t3, t4, s, A, B, SessionKey); //do we match the M sent by the client? if (M == M1) { Authed = true; // The account code will disconnect any other attached auth or realm sessions when we add an auth session to it await Account.AddSession(this); BigInteger M2 = BigInt.Hash(A, M, SessionKey); PacketOut p = new PacketOut(AuthOp.AUTH_LOGON_PROOF); p.Write((byte)AuthError.Success); p.WriteBigInt(M2, 20); p.Write((int)0); p.Write((int)0); p.Write((short)0); await SendPacket(p); } else { await SendAuthError(AuthError.NoAccount); } }
Task SendAuthError(AuthError error) { PacketOut p = new PacketOut(); p.w.Write((byte)AuthOp.AUTH_LOGON_CHALLENGE); p.w.Write((byte)0); p.w.Write((byte)error); SendPacket(p); return TaskDone.Done; }
public async Task OnRealmList() { if (!Authed) return; var realm_manager = GrainFactory.GetGrain<IRealmManager>(0); if (realm_manager == null) //something seriously went wrong! return; var realms = await realm_manager.GetRealms(); PacketOut p = new PacketOut(AuthOp.REALM_LIST); p.Write((UInt16)0); //size p.Write((int)0); //lets write a test realm! p.Write((UInt16)realms.Length); //realmCount foreach (var r in realms) { p.Write((byte)0); //type p.Write((byte)0); //status p.Write((byte)0); //flags p.WriteCString(r.RealmSettings.Name); p.WriteCString(r.RealmSettings.Address); p.Write(r.GetPopulationStatus()); p.Write((byte)1); //character count, TODO p.Write((byte)r.RealmSettings.Cat); p.Write((byte)0); //unknown } //this should be a loop based on realmcount in future //end loop p.Write((byte)0x10); p.Write((byte)0); //rewrite size p.strm.Position = 1; p.Write((UInt16)(p.strm.Length - 3)); p.strm.Position = p.strm.Length; await SendPacket(p); }
public void Write(PacketOut p) { p.Write(GUID); p.Write((UInt32)Flags); p.Write((UInt16)Flags2); p.Write(Time); p.Write(PositionX); p.Write(PositionY); p.Write(PositionZ); p.Write(PositionO); if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_ONTRANSPORT)) { if (MovementDataTransport == null) MovementDataTransport = new MovementDataTransport(); p.Write(MovementDataTransport.TransportGuid); p.Write(MovementDataTransport.TransportX); p.Write(MovementDataTransport.TransportY); p.Write(MovementDataTransport.TransportZ); p.Write(MovementDataTransport.TransportO); p.Write(MovementDataTransport.TransportTime); p.Write(MovementDataTransport.TransportSeat); if (Flags2.HasFlag(MovementFlags2.MOVEMENTFLAG2_INTERPOLATED_MOVEMENT)) p.Write(MovementDataTransport.TransportTime2); } if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_SWIMMING | MovementFlags.MOVEMENTFLAG_FLYING) || Flags2.HasFlag(MovementFlags2.MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING)) p.Write(Pitch); p.Write(FallTime); if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_FALLING)) { p.Write(FallVerticalSpeed); p.Write(FallSine); p.Write(FallCosine); p.Write(FallLateralSpeed); } if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_SPLINE_ELEVATION)) p.Write(SplineElevation); }
public static object Deserializer(System.Type expected, global::Orleans.Serialization.BinaryTokenStreamReader stream) { Shared.PacketOut result = new Shared.PacketOut(); object objResult = ((object)(result)); object temp1 = ((System.IO.MemoryStream)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(System.IO.MemoryStream), stream))); fieldInfo1.SetValue(objResult, temp1); object temp2 = ((Shared.PacketType)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Shared.PacketType), stream))); fieldInfo2.SetValue(objResult, temp2); return objResult; }
public static object DeepCopier(object original) { Shared.PacketOut input = ((Shared.PacketOut)(original)); Shared.PacketOut result = new Shared.PacketOut(); Orleans.Serialization.SerializationContext.Current.RecordObject(original, result); object objResult = ((object)(result)); object temp1 = ((System.IO.MemoryStream)(Orleans.Serialization.SerializationManager.DeepCopyInner(fieldInfo1.GetValue(input)))); fieldInfo1.SetValue(objResult, temp1); object temp2 = fieldInfo2.GetValue(input); fieldInfo2.SetValue(objResult, temp2); return objResult; }
public void SendPacket(PacketOut p) { p.Finalise(); var parray = p.strm.ToArray(); sock.Send(parray, parray.Length); }