public static void Handle(ulong clientId, Packet packet, SslStream stream) { Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); TdfUnion addr = (TdfUnion)data["ADDR"]; TdfStruct valu = (TdfStruct)addr.data.Find(tdf => tdf.label == "VALU"); TdfStruct inip = (TdfStruct)valu.data.Find(tdf => tdf.label == "INIP"); TdfInteger ip = (TdfInteger)inip.data.Find(tdf => tdf.label == "IP"); TdfInteger port = (TdfInteger)inip.data.Find(tdf => tdf.label == "PORT"); Log.Debug(string.Format("Updating internal network info for client {0}.", clientId)); ClientManager.UpdateClientInternalNetworkData(clientId, ip.value, (ushort)port.value); TdfEncoder encoder = new TdfEncoder(); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.USERSESSIONS, commandId = 0x14, 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); TdfInteger gid = (TdfInteger)data["GID"]; TdfUnion pnet = (TdfUnion)data["PNET"]; TdfStruct valu = (TdfStruct)pnet.data.Find(tdf => tdf.label == "VALU"); TdfStruct exip = (TdfStruct)valu.data.Find(tdf => tdf.label == "EXIP"); TdfInteger exipIP = (TdfInteger)exip.data.Find(tdf => tdf.label == "IP"); TdfInteger exipPort = (TdfInteger)exip.data.Find(tdf => tdf.label == "PORT"); TdfStruct inip = (TdfStruct)valu.data.Find(tdf => tdf.label == "INIP"); TdfInteger inipIP = (TdfInteger)inip.data.Find(tdf => tdf.label == "IP"); TdfInteger inipPort = (TdfInteger)inip.data.Find(tdf => tdf.label == "PORT"); var client = ClientManager.GetClient(clientId); if (Database.GameExists(gid.value)) { // update stuff ClientManager.UpdateClientInternalNetworkData(clientId, inipIP.value, (ushort)inipPort.value); ClientManager.UpdateClientExternalNetworkData(clientId, exipIP.value, (ushort)inipPort.value); ClientManager.UpdateClientGameID(clientId, (ulong)gid.value); Log.Info(string.Format("User {0} is joining game {1}.", client.user.id, gid.value)); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { new TdfInteger("GID", (ulong)gid.value), new TdfInteger("JGS", 0) }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.GAMEMANAGER, commandId = 0x9, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); var game = Database.GetGameByID(gid.value); var gameClient = ClientManager.GetClient(game.clientId); // TODO: check if only userupdated needed UserAddedNotification.Notify(clientId, stream, true); UserUpdatedNotification.Notify(client.persona.id, stream); JoiningPlayerInitiateConnectionsNotification.Notify(clientId, stream); UserSessionExtendedDataUpdateNotification.Notify(clientId, stream, true); PlayerJoiningNotification.Notify(clientId, gameClient.stream); PlayerClaimingReservationNotification.Notify(clientId, gameClient.stream); UserSessionExtendedDataUpdateNotification.Notify(clientId, gameClient.stream, true); } else { Log.Warn(string.Format("User {0} wanted to a game that doesn't exist ({1}).", client.user.id, gid.value)); /* * not sure if we should set the error code to GAMEMANAGER_ERR_NO_DEDICATED_SERVER_FOUND (0x12D0004) * or GAMEMANAGER_ERR_INVALID_GAME_ID (0x20004) * */ Utilities.SendPacket(new Packet { componentId = Component.GAMEMANAGER, commandId = 0x9, errorCode = 0x20004, // GAMEMANAGER_ERR_INVALID_GAME_ID msgType = MessageType.ERROR_REPLY, msgNum = packet.msgNum, payload = null, payloadSize = 0 }, stream); } }
public static void Handle(ulong clientId, Packet packet) { var client = ClientManager.GetClient(clientId); Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); TdfMap attr = (TdfMap)data["ATTR"]; TdfString gnam = (TdfString)data["GNAM"]; TdfInteger gset = (TdfInteger)data["GSET"]; TdfList pcap = (TdfList)data["PCAP"]; TdfInteger igno = (TdfInteger)data["IGNO"]; TdfInteger pmax = (TdfInteger)data["PMAX"]; TdfInteger nres = (TdfInteger)data["NRES"]; // network topology TdfInteger ntop = (TdfInteger)data["NTOP"]; TdfInteger voip = (TdfInteger)data["VOIP"]; TdfInteger pres = (TdfInteger)data["PRES"]; // TdfMin TdfInteger qcap = (TdfInteger)data["QCAP"]; //TdfString uuid = (TdfString)data["UUID"]; TdfList hnet = (TdfList)data["HNET"]; TdfStruct exip = (TdfStruct)hnet.list[0]; TdfInteger exipIP = (TdfInteger)exip.data.Find(tdf => tdf.label == "IP"); TdfInteger exipPort = (TdfInteger)exip.data.Find(tdf => tdf.label == "PORT"); TdfStruct inip = (TdfStruct)hnet.list[1]; TdfInteger inipIP = (TdfInteger)inip.data.Find(tdf => tdf.label == "IP"); TdfInteger inipPort = (TdfInteger)inip.data.Find(tdf => tdf.label == "PORT"); // TODO: don't get gameId as result but get by clientId after creating the game /* ulong gameId = GameManager.CreateGame( * * (int)gset.value, * (int)igno.value, * (int)nres.value, * (int)ntop.value, * "714b05dc-93bc-49ac-961c-cb38b574f30a" * ); */ var level = attr.map["level"].ToString(); var gametype = attr.map["levellocation"].ToString(); var game = new Database.Game(); game.clientId = clientId; game.name = gnam.value; game.attributes = attr.map; game.capacity = pcap.list; game.level = attr.map["level"].ToString(); game.gametype = attr.map["levellocation"].ToString(); game.maxPlayers = (ushort)pmax.value; game.notResetable = (byte)nres.value; game.queueCapacity = (ushort)qcap.value; game.presenceMode = (PresenceMode)pres.value; game.state = GameState.INITIALIZING; game.networkTopology = (GameNetworkTopology)ntop.value; game.voipTopology = (VoipTopology)voip.value; Database.NetworkInfo internalNetworkInfo = new Database.NetworkInfo(); internalNetworkInfo.ip = inipIP.value; internalNetworkInfo.port = (ushort)inipPort.value; Database.NetworkInfo externalNetworkInfo = new Database.NetworkInfo(); externalNetworkInfo.ip = exipIP.value; externalNetworkInfo.port = (ushort)exipPort.value; game.internalNetworkInfo = internalNetworkInfo; game.externalNetworkInfo = externalNetworkInfo; ulong gameId = Database.CreateGame(game); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { // this one is tdfmin new TdfInteger("GID", (ulong)gameId) }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.GAMEMANAGER, commandId = 0x1, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, client.stream); GameStateChangeNotification.Notify(gameId, game.state, client.stream); GameSetupNotification.Notify(clientId, gameId, client.stream); }
public static void Handle(ulong clientId, Packet packet, SslStream stream) { // decode payload Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload); // read client type TdfStruct cdat = (TdfStruct)data["CDAT"]; TdfInteger type = (TdfInteger)cdat.data.Find(tdf => tdf.label == "TYPE"); TdfString svcn = (TdfString)cdat.data.Find(tdf => tdf.label == "SVCN"); TdfStruct cinf = (TdfStruct)data["CINF"]; TdfInteger loc = (TdfInteger)cinf.data.Find(tdf => tdf.label == "LOC"); // set client type ClientManager.UpdateClientType(clientId, (ClientType)type.value); ClientManager.UpdateClientLocalization(clientId, loc.value); ClientManager.UpdateClientService(clientId, svcn.value); var client = ClientManager.GetClient(clientId); TdfList cids = new TdfList("CIDS", TdfBaseType.TDF_TYPE_INTEGER, new ArrayList { //1, 25, 4, 27, 28, 6, 7, 9, 10, 11, 30720, 30721, 30722, 30723, 20, 30725, 30726, 2000 }); cids.list.AddRange((new ulong[] { 1, 25, 4, 27, 28, 6, 7, 9, 10, 11, 30720, 30721, 30722, 30723, 20, 30725, 30726, 2000 }).ToArray()); TdfEncoder encoder = new TdfEncoder(); encoder.WriteTdf(new List <Tdf> { new TdfInteger("ANON", 0), new TdfString("ASRC", "300294"), cids, new TdfString("CNGN", ""), new TdfStruct("CONF", new List <Tdf> { new TdfMap("CONF", TdfBaseType.TDF_TYPE_STRING, TdfBaseType.TDF_TYPE_STRING, new Dictionary <object, object> { { "connIdleTimeout", "90s" }, { "defaultRequestTimeout", "80s" }, { "pingPeriod", "20s" }, { "voipHeadsetUpdateRate", "1000" }, { "xlspConnectionIdleTimeout", "300" } }) }), new TdfString("INST", client.service), new TdfInteger("MINR", 0), new TdfString("NASP", "cem_ea_id"), // TODO: check if present in decoded data new TdfString("PILD", ""), new TdfString("PLAT", "pc"), // TODO: fetch from decoded data new TdfString("PTAG", ""), new TdfStruct("QOSS", new List <Tdf> { // bandwidth ping site info new TdfStruct("BWPS", new List <Tdf> { new TdfString("PSA", "127.0.0.1"), // ping site address new TdfInteger("PSP", 17502), // ping site port new TdfString("SNA", "ams") // ping site name }), new TdfInteger("LNP", 10), // number of latency probes new TdfMap("LTPS", TdfBaseType.TDF_TYPE_STRING, TdfBaseType.TDF_TYPE_STRUCT, new Dictionary <object, object> { { "ams", new List <Tdf> { new TdfString("PSA", "127.0.0.1"), // ping site address new TdfInteger("PSP", 17502), // ping site port new TdfString("SNA", "ams") // ping site name } } }), new TdfInteger("SVID", 1161889797) // service ID }), new TdfString("RSRC", "300294"), new TdfString("SVER", "Blaze 3.15.08.0 (CL# 1060080)") }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.UTIL, commandId = 0x7, errorCode = 0, msgType = MessageType.REPLY, msgNum = packet.msgNum, payload = payload, payloadSize = payload.Length }, stream); }
public static void Notify(ulong clientId, SslStream stream, bool ulst = false) { var client = ClientManager.GetClient(clientId); TdfEncoder encoder = new TdfEncoder(); TdfList pslm = new TdfList("PSLM", TdfBaseType.TDF_TYPE_INTEGER, new ArrayList { }); pslm.list.AddRange(new ulong[] { 268374015, 268374015, 268374015, 268374015, 268374015 }); TdfStruct data = new TdfStruct("DATA", new List <Tdf> { new TdfUnion("ADDR", NetworkAddressMember.MEMBER_IPPAIRADDRESS, new List <Tdf> { new TdfStruct("VALU", new List <Tdf> { new TdfStruct("EXIP", new List <Tdf> { new TdfInteger("IP", client.externalNetworkInfo.ip), new TdfInteger("PORT", client.externalNetworkInfo.port) }), new TdfStruct("INIP", new List <Tdf> { new TdfInteger("IP", client.internalNetworkInfo.ip), new TdfInteger("PORT", client.internalNetworkInfo.port) }) }) }), new TdfString("BPS", "ams"), new TdfString("CTY", ""), new TdfInteger("HWFG", 0), pslm, new TdfInteger("UATT", 0) }); if (ulst == true) { data.data.Add(new TdfList("ULST", TdfBaseType.TDF_TYPE_BLAZE_OBJECT_ID, new ArrayList { new TdfVector3("0", 0x4, 0x1, client.gameId) })); } encoder.WriteTdf(new List <Tdf> { data, new TdfInteger("USID", client.persona.id) }); byte[] payload = encoder.Encode(); Utilities.SendPacket(new Packet { componentId = Component.USERSESSIONS, commandId = 0x1, errorCode = 0, msgType = MessageType.NOTIFICATION, msgNum = 0, payload = payload, payloadSize = payload.Length }, stream); }