示例#1
0
        private void HandlePacket(byte[] received)
        {
            ushort packetLength = BitConverter.ToUInt16(received, 0),
                   packetId     = BitConverter.ToUInt16(received, 2);

            switch (packetId)
            {
            case 1086:
            {
                string IP = (Socket?.RemoteEndPoint as System.Net.IPEndPoint).Address.ToString();
                Account = MsgAccountSRP6Ex.Deserialize(received);
                var tableInfo = new Tables.Accounts(Account.Username);
                if (!tableInfo.Found)
                {
                    Send(MsgConnectEx.Rejected(MsgConnectEx.RejectionCode.InvalidInfo));
                    return;
                }
                string enc = PasswordCryptography.EncryptPassword(tableInfo.Password);
                if (Account.Password != enc)
                {
                    Send(MsgConnectEx.Rejected(MsgConnectEx.RejectionCode.InvalidInfo));
                    Console.WriteLine($"[{IP}] {Account.Username} --> INVALID ON [{Account.Server}].");
                    return;
                }
                if (!Servers.ServersTable.ContainsKey(Account.Server))
                {
                    Console.WriteLine($"[{IP}] {Account.Username} --> [{Account.Server}] INVALID SERVER.");
                    Send(MsgConnectEx.Rejected(MsgConnectEx.RejectionCode.ServersNotConfigured));
                    return;
                }
                var server = Servers.ServersTable.Where(e => e.Key == Account.Server).SingleOrDefault().Value;
                if (!tableInfo.UIDS.ContainsKey(server.ID))
                {
                    uint lastuid = 0;
                    while (lastuid == 0)
                    {
                        lastuid = (uint)Config.GetLastUID();
                    }
                    tableInfo.UIDS.Add(server.ID, lastuid);        // Gets the next UID
                    Console.WriteLine($"[UID] [{lastuid}] created for user : {Account.Username} .");
                }
                Send(
                    MsgConnectEx.Verified(tableInfo.UIDS.Where(e => e.Key == server.ID).SingleOrDefault().Value,
                                          server.IP, server.Port));
                tableInfo.IPAddress = IP;
                tableInfo.FinalizeLogin();        // Save info to the database.
                Console.WriteLine($"[{IP}] {Account.Username} is transfered to {Account.Server} status : {tableInfo.Role.ToString()}.");
                break;
            }

            default:
            {
                Console.WriteLine($"Unknown packet-> Id: {packetId} Length: {packetLength}.");
                break;
            }
            }
        }
        private void GetFocusedRowData(int index)
        {
            if (index >= 0 && AccountStructureView.RowCount > 0)
            {
                AccountStructureView.FocusedRowHandle = index;
                btnSave.Enabled       = false;
                btnAddNew.Enabled     = btnModify.Enabled = btnDelete.Enabled = true;
                txtStructureCode.Text = AccountStructureView.GetRowCellValue(index,
                                                                             AccountStructureManager.AccountStructureDetails.StructureCode.ToString()).ToString();
                AccountStructure acst = accstructure.Get(int.Parse(txtStructureCode.Text));
                txtStructureName.Text = acst.StructureName;
                dt.Rows.Clear();
                // FinancialDeminsionView.Columns.Clear();
                FinancialDeminsionGrid.DataSource = null;
                foreach (StructureDeminsions item in acst.StructureDeminsions)
                {
                    Account.EditValue = item.AccCode;

                    dt.Rows.Add(item.FinCatCode, item.FinancialCategory.FinCatName);
                }
                FinancialDeminsionGrid.DataSource = dt;
                FinancialDeminsionGrid.DataMember = dt.TableName;
            }
        }
示例#3
0
文件: GameData.cs 项目: kibay/K-Relay
        public static void Load()
        {
            Parallel.Invoke(
                () =>
            {
                try
                {
                    Items = new GameDataMap <ushort, ItemStructure>(ItemStructure.Load(XDocument.Load("Objects.xml")));
                    PluginUtils.Log("GameData", "loaded items from file!");
                }
                catch
                {
                    Items = new GameDataMap <ushort, ItemStructure>(ItemStructure.Load(XDocument.Parse(RawObjectsXML)));
                }
                PluginUtils.Log("GameData", "Mapped {0} items.", Items.Map.Count);
            },
                () =>
            {
                try
                {
                    Tiles = new GameDataMap <ushort, TileStructure>(TileStructure.Load(XDocument.Load("Tiles.xml")));
                    PluginUtils.Log("GameData", "loaded tiles from file!");
                }
                catch
                {
                    Tiles = new GameDataMap <ushort, TileStructure>(TileStructure.Load(XDocument.Parse(RawTilesXML)));
                }
                PluginUtils.Log("GameData", "Mapped {0} tiles.", Tiles.Map.Count);
            },
                () =>
            {
                try
                {
                    Objects = new GameDataMap <ushort, ObjectStructure>(ObjectStructure.Load(XDocument.Load("Objects.xml")));
                    PluginUtils.Log("GameData", "loaded objects from file!");
                }
                catch
                {
                    Objects = new GameDataMap <ushort, ObjectStructure>(ObjectStructure.Load(XDocument.Parse(RawObjectsXML)));
                }
                PluginUtils.Log("GameData", "Mapped {0} objects.", Objects.Map.Count);
            },
                () =>
            {
                try
                {
                    Packets = new GameDataMap <byte, PacketStructure>(PacketStructure.Load(XDocument.Load("Packets.xml")));
                    PluginUtils.Log("GameData", "loaded packets from file!");
                }
                catch
                {
                    Packets = new GameDataMap <byte, PacketStructure>(PacketStructure.Load(XDocument.Parse(RawPacketsXML)));
                }
                PluginUtils.Log("GameData", "Mapped {0} packets.", Packets.Map.Count);
            },
                () =>
            {
                if (System.IO.File.Exists("Accounts.xml"))
                {
                    Accounts = new GameDataMap <string, AccountStructure>(AccountStructure.Load(XDocument.Load("Accounts.xml")));
                    PluginUtils.Log("GameData", "Mapped {0} accounts.", Accounts.Map.Count);
                }
            },
                () =>
            {
                const string CHAR_LIST_FILE = "char_list.xml";

                XDocument charList = null;

                try
                {
                    charList = XDocument.Load("https://www.realmofthemadgod.com/char/list");
                }
                catch (Exception)
                {
                }

                // If the char list doesn't contain an error
                if (charList != null && charList.Element("Error") == null)
                {
                    // Make a backup of the char list
                    charList.Save(CHAR_LIST_FILE);
                }
                // If the backup char list file exists
                else if (System.IO.File.Exists(CHAR_LIST_FILE))
                {
                    charList = XDocument.Load(CHAR_LIST_FILE);
                }
                // The retrieved char list contains an error and a backup char list doesn't exist
                else
                {
                    PluginUtils.Log("GameData", "Error! Unable to retrieve server list.");
                    return;
                }

                Servers = new GameDataMap <string, ServerStructure>(ServerStructure.Load(charList));
                PluginUtils.Log("GameData", "Mapped {0} servers.", Servers.Map.Count);
            });

            PluginUtils.Log("GameData", "Successfully loaded game data.");
        }