Пример #1
0
        private void RequestDuel(object sender, EventArgs e)
        {
            ListBox list = (UserListTabs.SelectedTab.Name == ChannelTab.Name ? ChannelList : UserList);
            if (list.SelectedItem == null)
            {
                return;
            }

            if ((list.SelectedItem is string ? list.SelectedItem.ToString() : ((UserData)list.SelectedItem).username) == Program.UserInfo.username)
            {
                WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "You cannot duel request your self."));
            }
            else
            {
                var form = new Host();
                ServerInfo server = Program.MainForm.GameWindow.GetServer();
                if (server == null)
                {
                    MessageBox.Show("No Server Available.");
                    return;
                }

                Program.ChatServer.SendPacket(DevServerPackets.RequestDuel,
                    JsonSerializer.SerializeToString(
                    new DuelRequest
                        {
                            username = list.SelectedItem is string ? list.SelectedItem.ToString() : ((UserData)list.SelectedItem).username, 
                            duelformatstring = form.GenerateGameString(false),
                            server = server.serverName
                        }));
                WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "Duel request sent to " + (list.SelectedItem is string ? list.SelectedItem.ToString() : ((UserData)list.SelectedItem).username) + "."));
            }
        }
Пример #2
0
        private void RequestDuel(object sender, EventArgs e)
        {
            ListBox list = (UserListTabs.SelectedTab.Name == OnlineTab.Name ? UserList : (UserListTabs.SelectedTab.Name == TeamTab.Name ? TeamList : FriendList));

            if (list.SelectedItem == null)
            {
                return;
            }

            if (list.SelectedItem.ToString() == Program.UserInfo.username)
            {
                WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "You cannot duel request your self."));
            }
            else
            {
                var form = new Host();
                Program.ChatServer.SendPacket(DevServerPackets.RequestDuel,
                    JsonSerializer.SerializeToString(
                    new DuelRequest
                        {
                        username = list.SelectedItem.ToString(),
                        duelformatstring = form.GenerateGameString(false)}));
                WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "Duel request sent to " + list.SelectedItem + "."));
            }
        }