public static void Handle(ulong clientId, Packet packet, SslStream stream) { var time = Utilities.GetUnixTime(); ClientManager.UpdateClientLastSeen(clientId, time); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { new TdfInteger("STIM", time) }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.UTIL, commandId = 0x2, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); }
public static void CleanClients() { lock (clients) { var canBeSafelyDeleted = (from client in clients where (Utilities.GetUnixTime() - client.Value.LastTouched) > 80000 select client.Key).ToList(); foreach (var client in canBeSafelyDeleted) { /* if (clients[client].type == ClientType.CLIENT_TYPE_DEDICATED_SERVER) * { * var gameId = clients[client].gameId; * * Log.Info(string.Format("Deleting game in CleanClients because {0}", (Utilities.GetUnixTime() - clients[client].LastTouched))); * * Database.DeleteGame(gameId); * } * * clients.Remove(client); */ } Log.Debug(string.Format("Deleted {0} clients.", canBeSafelyDeleted.Count)); canBeSafelyDeleted = null; } }
public static void Handle(ulong clientId, Packet packet, SslStream stream) { Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); TdfString pnam = (TdfString)data["PNAM"]; var client = ClientManager.GetClient(clientId); Log.Info(string.Format("User {0} logging in to persona {1}.", client.user.id, pnam.value)); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new TdfInteger("BUID", client.persona.id)); encoder.WriteTdf(new TdfInteger("FRST", 0)); encoder.WriteTdf(new TdfString("KEY", "10c38a80_a223eb9d6c2c199db1885856a297055d")); encoder.WriteTdf(new TdfInteger("LLOG", Utilities.GetUnixTime())); encoder.WriteTdf(new TdfString("MAIL", client.user.mail)); encoder.WriteTdf(new TdfStruct("PDTL", new List <Tdf> { new TdfString("DSNM", client.persona.name), // persona display name new TdfInteger("LAST", Utilities.GetUnixTime()), // time of last persona authentication new TdfInteger("PID", 0), // persona ID new TdfInteger("STAS", 2), // ACTIVE new TdfInteger("XREF", 0), new TdfInteger("XTYP", (ulong)ExternalRefType.BLAZE_EXTERNAL_REF_TYPE_UNKNOWN) // this is actually a TdfMin })); encoder.WriteTdf(new TdfInteger("UID", clientId)); // Blaze user ID byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.AUTHENTICATION, commandId = 0x6E, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); }
public static void Handle(ulong clientId, Packet packet, SslStream stream) { Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); TdfString mail = (TdfString)data["MAIL"]; TdfString pass = (TdfString)data["PASS"]; var client = ClientManager.GetClient(clientId); var user = Database.GetUser(mail.value, pass.value); if (user.id != 0) { Log.Info(string.Format("User {0} logging in with mail {1}.", user.id, user.mail)); } else { Log.Error(string.Format("Could not find user for user {0}.", user.id)); } ClientManager.SetClientUser(clientId, user); var persona = Database.GetPersona(user.personaId); if (persona.name != null) { Log.Debug(string.Format("Found persona '{0}' for user {1}.", persona.name, user.id)); } else { Log.Error(string.Format("Could not find persona for user {0}.", user.id)); } ClientManager.SetClientPersona(clientId, persona); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { new TdfString("LDHT", ""), new TdfInteger("NTOS", 0), new TdfString("PCTK", "NnQWcHUvUoE4gBscrqJNMx6QzKKrVnnbaZBnD4ZY9kEzKg0cBlW0TrCWil1I8GokLs9p0h_stN5UvWYaS3IrQEK6qvjFwY59k6R_NYIKCp4"), new TdfList("PLST", TdfBaseType.TDF_TYPE_STRUCT, new ArrayList { new List <Tdf> { new TdfString("DSNM", persona.name), new TdfInteger("LAST", Utilities.GetUnixTime()), new TdfInteger("PID", persona.id), new TdfInteger("STAS", 2), // 'ACTIVE' new TdfInteger("XREF", 0), new TdfInteger("XTYP", (ulong)ExternalRefType.BLAZE_EXTERNAL_REF_TYPE_UNKNOWN) } }), new TdfString("PRIV", ""), new TdfString("SKEY", "10c38a80_a223eb9d6c2c199db1885856a297055d"), new TdfInteger("SPAM", 1), new TdfString("THST", ""), new TdfString("TSUI", ""), new TdfString("TURI", ""), new TdfInteger("UID", clientId) }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.AUTHENTICATION, commandId = 0x28, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); }
public static void Handle(ulong clientId, Packet packet, SslStream stream) { Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); TdfString auth = (TdfString)data["AUTH"]; ClientManager.UpdateClientAuthToken(clientId, auth.value); TdfInteger pid = (TdfInteger)data["PID"]; var user = Database.GetUser(pid.value); if (user.mail != null) { ClientManager.SetClientUser(clientId, user); } else { Log.Warn(string.Format("Could not find user by persona ID {0}.", pid.value)); } Log.Info(string.Format("Performing silent login with persona {0} for user {1}.", pid.value, user.id)); var persona = Database.GetPersona(pid.value); if (persona.name != null) { //Log.Info(string.Format("User {0} logging in to persona {1} with auth token {2}.", user.id, persona.name, auth.value)); ClientManager.SetClientPersona(clientId, persona); } else { Log.Warn(string.Format("Could not find persona {0} for user {1}.", pid.value, user.id)); } // not sure what is this type for //TdfInteger type = (TdfInteger)data.Find(tdf => tdf.label == "TYPE"); var client = ClientManager.GetClient(clientId); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { new TdfInteger("AGUP", 0), new TdfString("LDHT", ""), new TdfInteger("NTOS", 0), new TdfString("PCTK", "fa1a26c1-d934-422a-a6ba-ed92614f7d87"), new TdfString("PRIV", ""), new TdfStruct("SESS", new List <Tdf> { new TdfInteger("BUID", client.persona.id), new TdfInteger("FRST", 0), new TdfString("KEY", "some_key"), new TdfInteger("LLOG", Utilities.GetUnixTime()), new TdfString("MAIL", client.user.mail), // TODO: get mail for client new TdfStruct("PDTL", new List <Tdf> { new TdfString("DSNM", client.persona.name), // persona display name new TdfInteger("LAST", Utilities.GetUnixTime()), // time of last persona authentication new TdfInteger("PID", client.persona.id), // persona ID new TdfInteger("STAS", 0), // should be ACTIVE(2)? new TdfInteger("XREF", 0), new TdfInteger("XTYP", (ulong)ExternalRefType.BLAZE_EXTERNAL_REF_TYPE_UNKNOWN) // this is actually a TdfMin }), new TdfInteger("UID", clientId) }), new TdfInteger("SPAM", 0), new TdfString("THST", ""), new TdfString("TSUI", ""), new TdfString("TURI", "") }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.AUTHENTICATION, commandId = 0x32, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); }