public static void Handle(ulong clientId, Packet packet, SslStream stream)
        {
            TdfEncoder encoder = new TdfEncoder();

            TdfMap smap = new TdfMap("SMAP", TdfBaseType.TDF_TYPE_STRING, TdfBaseType.TDF_TYPE_STRING, new Dictionary <object, object>
            {
                { "cust", "" } // TODO: fetch from userSettingsSave - 0x000B
            });

            encoder.WriteTdf(new List <Tdf>
            {
            });

            byte[] payload = encoder.Encode();

            Utilities.SendPacket(new Packet
            {
                componentId = Component.UTIL,
                commandId   = 0xC,
                errorCode   = 0,
                msgType     = MessageType.REPLY,
                msgNum      = packet.msgNum,

                payload     = payload,
                payloadSize = payload.Length
            }, stream);
        }
        public static void Handle(ulong clientId, Packet packet, SslStream stream)
        {
            TdfEncoder encoder = new TdfEncoder();

            TdfMap smap = new TdfMap("SMAP", TdfBaseType.TDF_TYPE_STRING, TdfBaseType.TDF_TYPE_STRING, new Dictionary<object, object>
            {
                { "cust", "" } // TODO: fetch from userSettingsSave - 0x000B
            });

            encoder.WriteTdf(new List<Tdf>
            {

            });

            byte[] payload = encoder.Encode();

            Utilities.SendPacket(new Packet
            {
                componentId = Component.UTIL,
                commandId = 0xC,
                errorCode = 0,
                msgType = MessageType.REPLY,
                msgNum = packet.msgNum,

                payload = payload,
                payloadSize = payload.Length
            }, stream);
        }
예제 #3
0
        private TdfMap DecodeTdfMap(string label)
        {
            // read list types
            TdfBaseType listType1 = (TdfBaseType)_stream.ReadByte();
            TdfBaseType listType2 = (TdfBaseType)_stream.ReadByte();

            // read list size
            int listSize = _stream.ReadByte();

            TdfMap map = new TdfMap(label, listType1, listType2, new Dictionary <object, object>());

            // read list
            Func <TdfBaseType, Object> readListItem = (type) =>
            {
                Object item = null;

                switch (type)
                {
                case TdfBaseType.TDF_TYPE_INTEGER:
                    item = DecodeInteger();
                    break;

                case TdfBaseType.TDF_TYPE_STRING:
                    item = DecodeString();
                    break;

                case TdfBaseType.TDF_TYPE_STRUCT:
                    item = DecodeStruct();
                    break;

                default:
                    Log.Warn(string.Format("Unknown list item type: {0}.", type));
                    break;
                }

                return(item);
            };

            for (int i = 0; i < listSize; i++)
            {
                Object key   = readListItem(listType1);
                Object value = readListItem(listType2);

                if (key != null | value != null)
                {
                    map.map.Add(key, value);
                }
            }

            return(map);
        }
예제 #4
0
        private void WriteTdfMap(TdfMap tdf)
        {
            // write list types
            _stream.WriteByte((byte)tdf.type1);
            _stream.WriteByte((byte)tdf.type2);

            // write list size
            _stream.WriteByte((byte)tdf.map.Count);

            // write map
            Action <TdfBaseType, Object> writeListItem = (type, item) =>
            {
                switch (type)
                {
                case TdfBaseType.TDF_TYPE_INTEGER:
                    WriteInteger((ulong)item);
                    break;

                case TdfBaseType.TDF_TYPE_STRING:
                    WriteString((string)item);
                    break;

                case TdfBaseType.TDF_TYPE_STRUCT:
                    WriteStruct((List <Tdf>)item);
                    break;

                default:
                    Log.Warn(string.Format("Unknown list item type: {0}.", type));
                    break;
                }
            };

            foreach (var item in tdf.map)
            {
                writeListItem(tdf.type1, item.Key);
                writeListItem(tdf.type2, item.Value);
            }
        }
        public static void Handle(ulong clientId, Packet packet, SslStream stream)
        {
            Dictionary <string, Tdf> data = Utilities.DecodePayload(packet.payload);

            TdfMap     attr = (TdfMap)data["ATTR"];
            TdfInteger gid  = (TdfInteger)data["GID"];

            Log.Info(string.Format("Setting game attributes for game {0}.", gid.value));

            var game       = Database.GetGameByID(gid.value);
            var attributes = game.attributes;

            foreach (var key in attr.map.Keys)
            {
                attributes[key] = attr.map[key];
            }

            Database.UpdateGameAttributes(gid.value, attributes);

            TdfEncoder encoder = new TdfEncoder();

            byte[] payload = encoder.Encode();

            Utilities.SendPacket(new Packet
            {
                componentId = Component.GAMEMANAGER,
                commandId   = 0x7,
                errorCode   = 0,
                msgType     = MessageType.REPLY,
                msgNum      = packet.msgNum,

                payload     = payload,
                payloadSize = payload.Length
            }, stream);

            GameAttribChangeNotification.Notify(gid.value, attr.map, stream);
        }
예제 #6
0
        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);
        }