示例#1
0
        public int HandlePacket(BaseClient client, PacketIn packet)
        {
            LobbyClient cclient = (LobbyClient)client;

            PacketOut Out      = new PacketOut((uint)Opcodes.ANS_CHARACTER_CREATE);
            byte      freeSlot = GetFreeSlot(cclient);

            if (freeSlot == 0)
            {
                Out.WriteInt32Reverse((int)ResponseCodes.RC_FAILED);
            }
            else
            {
                cclient.Pending.Slot    = freeSlot;
                cclient.Pending.Faction = packet.GetUint8();
                cclient.Pending.Gender  = packet.GetUint8();
                cclient.Pending.Version = (byte)packet.GetUint32Reversed();
                packet.GetUint32Reversed();
                byte[] Custom = new byte[packet.Length - packet.Position];
                packet.Read(Custom, 0, Custom.Length);
                cclient.Pending.Appearance = BitConverter.ToString(Custom);
                Databases.CharacterTable.Add(cclient.Pending);
                Out.WriteInt32Reverse((int)ResponseCodes.RC_SUCCESS);
                Out.WriteInt32Reverse(cclient.Pending.Slot);
            }
            cclient.Send(Out);
            System.Threading.Thread.Sleep(500);
            cclient.Pending = default(CharacterEntry);
            System.Threading.Thread.Sleep(500);
            cclient.Disconnect();
            return(0);
        }
示例#2
0
    void OnChatStart(string primaryKey, string messageId, string messageText)
    {
        JsonData data   = JsonMapper.ToObject(messageText);
        string   master = data["master"].ToString();
        string   slave  = data["slave"].ToString();

        var  friend   = GameCloudManager.friendList.friends.Find(obj => obj.PrimaryKey == master);
        bool isFriend = friend != null ? true : false;

        primaryKey = m_PrimaryKey == master ? slave : master;
        FriendInfo info = m_Friends.Find(obj => obj.PrimaryKey == primaryKey);

        if (GuiFrontendMain.IsVisible == false || isFriend == false || JoinChat(master, slave, false) == false)
        {
            var result = new
            {
                master = master,
                slave  = slave
            };
            LobbyClient.SendMessageToPlayer(master == m_PrimaryKey ? slave : master, CMD_FAILED, JsonMapper.ToJson(result));
        }
        else
        {
            if (info == null)
            {
                info = m_Friends.Find(obj => obj.PrimaryKey == primaryKey);
                AddSystemMessage(info, string.Format(TextDatabase.instance[0506011], GuiBaseUtils.FixNameForGui(info.Nickname)));
            }
        }
    }
示例#3
0
        static public void Send(LobbyClient client)
        {
            PacketOut Out = new PacketOut((uint)Opcodes.LOGIN_PUZZLE);

            if (Program.version == GameVersion.RTW_LAST)
            {
                Out.WriteInt32Reverse(1);
                Out.WriteInt32Reverse(4);
                Out.WriteInt32Reverse(1);
                Out.WriteInt32Reverse(555239);
            }
            else if (Program.version == GameVersion.G1_LATEST)
            {
                Out.WriteInt32Reverse(1);
                Out.WriteInt32Reverse(19);
                Out.WriteInt32Reverse(4);
                Out.WriteInt32Reverse(775065);
            }
            Out.WriteByte(0x05);
            for (int i = 0; i < client.ECrypt.Key.Length; i++)
            {
                Out.WriteByte(client.ECrypt.Key[i]);
            }
            Out.WriteUInt32Reverse(0);
            Out.WriteUInt32Reverse(0);
            Out.WriteUInt32Reverse(0);
            client.SendTCP(Out);
        }
示例#4
0
    void LeaveChat(int friendIdx, bool informOtherSide)
    {
        if (friendIdx < 0 || friendIdx >= m_Friends.Count)
        {
            return;
        }

        FriendInfo info = m_Friends[friendIdx];

        m_Friends.RemoveAt(friendIdx);
        if (info == null)
        {
            return;
        }

        if (informOtherSide == true && info.IsJoined == true)
        {
            var result = new
            {
                master = info.Master,
                slave  = info.Slave
            };
            LobbyClient.SendMessageToPlayer(info.Master == m_PrimaryKey ? info.Slave : info.Master, CMD_LEAVE, JsonMapper.ToJson(result));
        }

        Chat.Unregister(info.Channel, this);

        info.Master = null;
        info.Slave  = null;

        ActivateChat(Mathf.Min(friendIdx, m_Friends.Count - 1));
    }
示例#5
0
        public int HandlePacket(BaseClient client, PacketIn packet)
        {
            LobbyClient cclient  = (LobbyClient)client;
            PacketOut   Out      = new PacketOut((uint)Opcodes.ANS_CHARACTER_CREATE);
            byte        freeSlot = GetFreeSlot(cclient);

            if (freeSlot == 0)
            {
                Out.WriteInt32Reverse((int)ResponseCodes.RC_FAILED);
            }
            else
            {
                cclient.Pending.Slot    = freeSlot;
                cclient.Pending.Faction = packet.GetUint8();
                cclient.Pending.Gender  = packet.GetUint8();
                cclient.Pending.Version = (byte)packet.GetUint32Reversed();
                packet.GetUint32Reversed();
                packet.GetUint32Reversed();
                byte[] Custom = new byte[packet.Length - packet.Position];
                packet.Read(Custom, 0, Custom.Length);
                byte[] ActualCustom = new byte[Custom.Length + 4];
                ActualCustom[0] = 0x36;
                ActualCustom[1] = 0x00;
                ActualCustom[2] = 0x00;
                ActualCustom[3] = 0x00;
                Buffer.BlockCopy(Custom, 0, ActualCustom, 4, Custom.Length);
                cclient.Pending.Appearance = BitConverter.ToString(ActualCustom);
                Databases.CharacterTable.Add(cclient.Pending);
                Out.WriteInt32Reverse((int)ResponseCodes.RC_SUCCESS);
                Out.WriteInt32Reverse(cclient.Pending.Slot);
            }
            cclient.Send(Out);
            return(0);
        }
示例#6
0
        public LobbyWindow(string username, string password)
        {
            this.username = username;
            InitializeComponent();
            LobbyProxy = new LobbyClient(new InstanceContext(this));
            LobbyProxy.SubscribeToLobbyEvents(username, password);

            labelUsername.Content = "Welcome " + username;

            // Get online players and show them in the list
            var onlinePlayers = LobbyProxy.GetOnlineList();

            if (onlinePlayers.Count() > 0)
            {
                inviteButton.IsEnabled = true;
            }

            foreach (var item in onlinePlayers)
            {
                listOnlinePlayers.Children.Add(new PlayerListElementControl(item));
            }

            if (LobbyProxy.GetSavedGmes(username).Count == 0)
            {
                SavedGameList.Items.Add("No Saved Game..");
            }
            else
            {
                foreach (var item in LobbyProxy.GetSavedGmes(username))
                {
                    SavedGameList.Items.Add(item);
                }
            }
        }
示例#7
0
        public int HandlePacket(BaseClient client, PacketIn packet)
        {
            LobbyClient    cclient = client as LobbyClient;
            byte           slotId  = packet.GetUint8();
            CharacterEntry Info    = Databases.CharacterTable.SingleOrDefault(c => c.AccountIndex == cclient.Account.Index && c.Slot == slotId);

            PacketOut Out = new PacketOut((uint)Opcodes.ANS_CHARACTER_INFO);

            if (Info.Index < 1)
            {
                Out.WriteUInt32Reverse((uint)ResponseCodes.RC_FAILED);
            }
            else
            {
                Out.WriteUInt32Reverse((uint)ResponseCodes.RC_SUCCESS);
                Out.WriteByte(Info.Slot);
                Out.WriteByte(Info.Gender);
                Out.WriteUInt32Reverse((uint)Info.Playtime);
                Out.WriteUInt32Reverse((uint)Info.Rank);
                Out.WriteByte(Info.Threat);
                Out.WriteUInt32Reverse((uint)Info.Money);
                Out.WriteParsedString(Info.Clan, 60);
                byte[] Custom = getCustom(Info);
                Out.Write(Custom, 0, Custom.Length);
            }
            cclient.Send(Out);
            return(0);
        }
示例#8
0
 void Start()
 {
     try{
         clientLobby = GameObject.Find("LobbyClient").GetComponent <LobbyClient> ();
     }catch {
     }
 }
示例#9
0
    void OnSearchingInvitedGame(int clientJoinRequestId, string invitingPrimaryKey)
    {
        //Popup.Show( TextDatabase.instance[0109061], "Searching for a suitable game...", "Cancel", OnMessageBoxEvent );
        m_MessageBox =
            (GuiPopupMessageBox)
            Owner.ShowPopup("MessageBox",
                            TextDatabase.instance[0109061],
                            TextDatabase.instance[0109058],
                            (inPopup, inResult) =>
        {
            //inPopup.ForceClose();
            m_MessageBox = null;

            if (inResult == E_PopupResultCode.Ok)
            {
                //FIXME We do not have the id now on the client side. Reimplement later.
                // The problem here is that this client does not pass any information to the lobby.
                // All the communication happens between the master (inviter) and the lobby. The childs (friends) receives just the OnSearchingInvitedGame a notification.
                LobbyClient.CancelFindServer(-1);

                UpdateStatus(m_Master, false);
                LeaveGang(m_Master);
            }
        });
        m_MessageBox.SetButtonText(TextDatabase.instance[02040009]);
    }
示例#10
0
        public int HandlePacket(BaseClient bcclient, PacketIn packet)
        {
            LobbyClient client = bcclient as LobbyClient;

            packet.Skip(25);
            string Username = packet.GetParsedString();

            Log.Notice("ASK_LOGIN", "Account: " + Username);
            try
            {
                client.Account = Databases.AccountTable.SingleOrDefault(a => a.Username == Username);
                if (client.Account.Verifier.Length <= 2 || client.Account.Salt.Length <= 2)
                {
                    Register(client);
                }
                client.Salt     = new FrameWork.NetWork.Crypto.BigInteger(client.Account.Salt, 16).ToByteArrayUnsigned();
                client.Verifier = new FrameWork.NetWork.Crypto.BigInteger(client.Account.Verifier, 16);
                Log.Succes("ASK_LOGIN", "Account exists: " + client.Account.Username);
                LOGIN_SALT.Send(client);
            }
            catch (ArgumentNullException)
            {
                Log.Error("ASK_LOGIN", "Database is busy");
                LOGIN_FAILED.Send(client, (int)ResponseCodes.RC_DATABASE_BUSY);
                client.Disconnect();
            }
            catch (Exception e)
            {
                Log.Error("ASK_LOGIN", "Account is not found");
                Log.Debug("ASK_LOGIN", e.ToString());
                LOGIN_FAILED.Send(client, (int)ResponseCodes.RC_LOGIN_INVALID_ACCOUNT);
                client.Disconnect();
            }
            return(0);
        }
示例#11
0
    void OnAddFriend(int rowIdx, GUIBase_Widget widget, object evt)
    {
        LobbyGang.FriendInfo friend = GetFriendByRowIdx(rowIdx);
        if (friend == null)
        {
            return;
        }
        if (friend.CanInvite == false)
        {
            return;
        }
        if (friend.IsInvited == true)
        {
            return;
        }

        friend.IsInvited = true;
        friend.IsWaiting = true;

        // send invite
        var data = new
        {
            master   = m_PrimaryKey,
            gametype = m_GametypeRoller.Selection
        };

        LobbyClient.SendMessageToPlayer(friend.PrimaryKey, LobbyGangMessage.INVITE, JsonMapper.ToJson(data));

        SetDirty();
    }
示例#12
0
 public byte GetFreeSlot(LobbyClient client)
 {
     try
     {
         byte[] slots = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
         if (client.Characters.Count != 0)
         {
             for (int i = 0; i < slots.Length; i++)
             {
                 foreach (CharacterEntry ch in client.Characters)
                 {
                     if (ch.Slot != slots[i])
                     {
                         return(slots[i]);
                     }
                     else
                     {
                         return(1);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(0);
     }
     return(0);
 }
示例#13
0
        static public void Send(LobbyClient client)
        {
            client.Characters = Databases.CharacterTable.Select(c => c.AccountIndex == client.Account.Index);
            PacketOut Out = new PacketOut((uint)Opcodes.CHARACTER_LIST);

            Out.WriteByte((byte)client.Characters.Count);
            lock (Program.worldListener.Worlds)
            {
                foreach (CharacterEntry chr in client.Characters)
                {
                    Out.WriteByte(chr.Slot);
                    Out.WriteByte(chr.Faction);
                    Out.WriteByte(1);
                    Out.WriteUInt32Reverse((uint)chr.World);
                    World.World info = null;
                    Program.worldListener.Worlds.TryGetValue((uint)chr.World, out info);
                    if (info != null)
                    {
                        Out.WriteParsedString(info.Name, 32);
                    }
                    else
                    {
                        Out.WriteParsedString("(undefined)", 32);
                    }
                    Out.WriteParsedString(chr.Name, 32);
                }
            }
            client.Send(Out);
            if (client.Characters.Count <= 0)
            {
                WORLD_LIST.SendWorldList(client);
            }
        }
示例#14
0
        static public void Send(LobbyClient client, int code)
        {
            PacketOut packet = new PacketOut((uint)Opcodes.ANS_LOGIN_FAILED);

            packet.WriteInt32Reverse(code);
            client.Send(packet);
        }
示例#15
0
        public void AddPlayer_ShouldWork()
        {
            var lobby = new LobbyClient();

            lobby.AddPlayer(new PlayerClient("Some Player"));
            Assert.NotEmpty(lobby.Players);
        }
示例#16
0
    static void CreateInstance()
    {
        GameObject go = new GameObject("LobbyClient");

        GameObject.DontDestroyOnLoad(go);

        m_Instance = go.AddComponent <LobbyClient>() as LobbyClient;
    }
示例#17
0
    static void DestroyInstance()
    {
        GameObject.Destroy(m_Instance);
        m_Instance = null;

        GameObject.DestroyImmediate(m_InstanceGameObject);
        m_InstanceGameObject = null;
    }
示例#18
0
    // PUBLIC METHODS

    public static bool ShowLoginMenu()
    {
        //FIXME it does work but there could be some potential problem in the future because this message is called
        //  each tick when player log-outs from his/her account (and stays in login screen)
        LobbyClient.DisconnectFromLobby();

        return(OpenMenu(E_MenuState.Login));
    }
示例#19
0
        public void RemovePlayerByName_FromEmptyLobbyShouldReturnZero()
        {
            var lobby = new LobbyClient();

            var result = lobby.RemovePlayerByName("Nonexistent Player");

            Assert.Equal(0, result);
        }
示例#20
0
        public static void Send(LobbyClient cclient, string Reason, string Information)
        {
            PacketOut Out = new PacketOut((uint)Opcodes.KICK);

            Out.WriteParsedString(Reason);
            Out.WriteParsedString(Information);
            cclient.Send(Out);
        }
示例#21
0
        public LobbyMenu(bool isHost, MatchSettings settings = null) : base("Lobby")
        {
            if (isHost && settings == null)
            {
                throw new ArgumentNullException("settings must not be null when isHost is true");
            }

            IsHost        = isHost;
            MatchSettings = settings;

            Close += (s, e) =>
            {
                if (isHost)
                {
                    Lobby?.CloseHostedGameAsync();
                    Lobby?.Dispose();
                    Lobby = null;
                }

                Ballz.The().Network.PlayerListChanged -= UpdatePlayerList;
            };

            Open += (s, e) =>
            {
                Ballz.The().Network.PlayerListChanged += UpdatePlayerList;

                UpdatePlayerList(this, Ballz.The().Network.PlayerList);

                if (isHost)
                {
                    Lobby = new LobbyClient();
                    var gameInfo = Lobby.MakeGameInfo(MatchSettings.GameName, MatchSettings.IsPrivate);
                    Ballz.The().Network.StartServer(gameInfo);
                    Lobby.OpenGame(gameInfo, Ballz.The().Network.NetworkPeer);
                }
            };

            AddItem(new Label("Players in Lobby:"));
            PlayerList = new SelectList();
            PlayerList.LockSelection = true;
            AddItem(PlayerList);

            if (isHost)
            {
                var startGameBtn = new Button("Start Game");
                startGameBtn.OnClick += (e) =>
                {
                    Ballz.The().Network.StartNetworkGame(MatchSettings, 0);
                };
                AddItem(startGameBtn);
            }
            else
            {
                AddItem(new Label("Waiting for Host to start the Game"));
            }

            AddItem(new BackButton(text: "Leave Game"));
        }
示例#22
0
        private static PlayerConnectionInfo CreateServerPeerConnectionInfo()
        {
            PlayerConnectionInfo playerConnectionInfo = new PlayerConnectionInfo();
            LobbyClient          gameClient           = NetworkMain.GameClient;

            playerConnectionInfo.AddParameter("PlayerData", (object)gameClient.PlayerData);
            playerConnectionInfo.Name = gameClient.Name;
            return(playerConnectionInfo);
        }
示例#23
0
        static void Main(string[] args)
        {
            var result = Launcher.OauthLogin("accountname", "password");
            var uid    = Launcher.RegisterSession(result);
            var lobby  = new LobbyClient(LobbyClient.Datacenter.NACrystal, uid.Uid, (Byte)result.MaxExpansion);

            Console.WriteLine("press any key to exit");
            Console.ReadLine();
        }
 void OnSaid(object sender, LobbyClient.Legacy.TasSayEventArgs args)
 {
     var tas = (LobbyClient.Legacy.TasClient)sender;
     if (args.Place == LobbyClient.Legacy.TasSayEventArgs.Places.Channel && channels.Contains(args.Channel) && args.UserName != tas.UserName)
     {
         var otherTas = zkTas;
         otherTas.Say(SayPlace.Channel, args.Channel, string.Format("<{0}> {1}", args.UserName, args.Text), args.IsEmote);
     }
 }
示例#25
0
        public void GetPlayerByName_NullPlayerShouldThrowException()
        {
            var lobby  = new LobbyClient();
            var player = new PlayerClient("player");

            lobby.AddPlayer(player);

            Assert.Throws <ArgumentException>(() => lobby.GetPlayerByName(null));
        }
示例#26
0
        public void SetDrawingPlayer_NonexistentPlayerPassed_ThrowError()
        {
            var lobby  = new LobbyClient();
            var player = new PlayerClient("player");

            lobby.AddPlayer(player);

            Assert.Throws <ArgumentException>(() => lobby.SetDrawingPlayer("nonexistent"));
        }
    private void disconnectAvatarFromClients(RemoveClient clientToRemove)
    {
        for (int i = 0; i < _clients.Count; i++)
        {
            LobbyClient client = _clients[i];

            sendObject(client.TcpClient, clientToRemove);
        }
    }
示例#28
0
        public void EachLobbyHasDifferentInviteLinkByDefault()
        {
            //arrange&act
            var lobbyA = new LobbyClient();
            var lobbyB = new LobbyClient();

            //assert
            Assert.NotEqual(lobbyA.InviteLink, lobbyB.InviteLink);
        }
示例#29
0
        public void ChangeConnectionForPlayer_NonexistentPlayerPassed_ThrowError()
        {
            var lobby  = new LobbyClient();
            var player = new PlayerClient("player");

            lobby.AddPlayer(player);

            Assert.Throws <ArgumentException>(() => lobby.ChangeConnectionForPlayer("nonexistent", true));
        }
示例#30
0
        private void InitServer()
        {
            var player = new Player(Properties.Settings.Default.UserName, START_ID, true, true)
            {
                IPAddress = NetUtils.GetAddress()
            };

            lobbyClient = new LobbyClient(player);
            lobbyClient.SetLobbyTcp(player.IPAddress, gameServer.Port);
        }
示例#31
0
        public void AddPlayer_UsernameAlreadyInLobbyShouldThrowException()
        {
            var lobby   = new LobbyClient();
            var player  = new PlayerClient("player");
            var player2 = new PlayerClient("player");

            lobby.AddPlayer(player);

            Assert.Throws <UserNameAlreadyExistsException>(() => lobby.AddPlayer(player2));
        }
示例#32
0
文件: Test.cs 项目: briandealwis/gt
        public Test()
        {
            Client client = new Client();
            Thread t = client.StartListeningOnSeperateThread(10);

            string name = Prompt.Show("What is your name?");

            if (name == null)
                return;

            LobbyClient lobby = new LobbyClient(name,
                new SimpleSharedDictionary(
                    client.OpenBinaryChannel("127.0.0.1","9999", 0)));
            Console.WriteLine("Lobby started.");
            lobby.ShowDialog();

            t.Abort();

            if (lobby.JoinedServer != null)
            {
                Console.WriteLine("We should connect to " + lobby.JoinedServer.IPAddress + ":" + lobby.JoinedServer.Port);
            }
        }
示例#33
0
        private void LClient_eLobbyChat(LobbyClient.LobbyChatTypes type, string user, string chat, bool inXaml)
        {
            rtbChat.Dispatcher.Invoke
            (
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action
                (
                    delegate()
                    {
                        if(rtbChat == null)
                            return;
                        bool rtbatbottom = false;
                        //check to see if the richtextbox is scrolled to the bottom.
                        //----------------------------------------------------------------------------------
                        double dVer = rtbChat.VerticalOffset;

                        //get the vertical size of the scrollable content area
                        double dViewport = rtbChat.ViewportHeight;

                        //get the vertical size of the visible content area
                        double dExtent = rtbChat.ExtentHeight;

                        if(dVer != 0)
                        {
                            if(dVer + dViewport == dExtent)
                            {
                                rtbatbottom = true;
                                justScrolledToBottom = false;
                            }
                            else
                            {
                                if(!justScrolledToBottom)
                                {
                                    Paragraph pa = new Paragraph();
                                    Run ru = new Run("------------------------------");
                                    ru.Foreground = Brushes.Red;
                                    pa.Inlines.Add(new Bold(ru));
                                    rtbChat.Document.Blocks.Add(pa);
                                    justScrolledToBottom = true;
                                }
                            }
                        }
                        //----------------------------------------------------------------------------------

                        Paragraph p = new Paragraph();
                        Run r;
                        Brush b;
                        switch(type)
                        {
                            case LobbyClient.LobbyChatTypes.Global:
                                r = getUserRun(user, "[" + user + "]: ");
                                if(user.Length > 5)
                                {
                                    if(user.Substring(0, 5).ToLower().Equals("<irc>"))
                                        b = System.Windows.Media.Brushes.DarkGray;
                                    else
                                        b = System.Windows.Media.Brushes.Black;
                                }
                                else
                                    b = System.Windows.Media.Brushes.Black;
                                if(user.Equals(Program.LClient.strUserName))
                                    b = Brushes.Blue;

                                r.Foreground = b;

                                p.Inlines.Add(new Bold(r));
                                break;
                            case LobbyClient.LobbyChatTypes.System:
                                r = new Run("#" + user + ": ");
                                b = Brushes.Red;
                                r.ToolTip = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString();
                                if(user.Equals("SUPPORT"))
                                    r.Foreground = Brushes.White;
                                else
                                {
                                    Program.TraceWarning("#" + user + ": " + chat);
                                    r.Foreground = b;
                                }
                                r.Cursor = Cursors.Hand;
                                //r.Background = Brushes.White;

                                p.Inlines.Add(new Bold(r));
                                if(user.Equals("SUPPORT"))
                                {
                                    try
                                    {
                                        rtbChat.Document.Blocks.Add(p);
                                        //Put xaml into rtb-------------------------------------------------------------
                                        StringReader stringReader = new StringReader(chat);
                                        System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);
                                        FlowDocument d = XamlReader.Load(xmlReader) as FlowDocument;
                                        Section s = new Section();
                                        s.BorderBrush = Brushes.Black;
                                        s.BorderThickness = new Thickness(1);
                                        s.Blocks.Add(p);
                                        GradientStopCollection gsc = new GradientStopCollection();
                                        gsc.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#e8c1c0"), 0));
                                        gsc.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#c42123"), .4));
                                        gsc.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#ea3a3c"), 1));
                                        s.Background = new LinearGradientBrush(gsc, (double)90.0);

                                        while(d.Blocks.Count > 0)
                                        {
                                            Block block = d.Blocks.FirstBlock;
                                            //block.BorderBrush = Brushes.Red;
                                            //block.BorderThickness = new Thickness(1);
                                            block.Foreground = Brushes.White;
                                            s.Blocks.Add(block);
                                            //richTextBox1.Document.Blocks.Add(block);
                                        }
                                        rtbChat.Document.Blocks.Add(s);
                                        //-------------------------------------------------------------------------------------------------------------
                                        if(rtbatbottom)
                                        {
                                            rtbChat.ScrollToEnd();
                                        }
                                        if(Settings.Default.LobbySound && !Program.lwLobbyWindow.IsActive)
                                        {
                                            System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.click);
                                            sp.Play();
                                        }
                                    }
                                    catch(Exception e)
                                    {
                                        if(chat != null)
                                            ErrorLog.WriteError(e, chat, false);
                                        else
                                            ErrorLog.WriteError(e, "null chat", false);
                                    }
                                    return;
                                }
                                break;
                            case LobbyClient.LobbyChatTypes.Whisper:
                                String[] w = user.Split(new char[1] { ':' });
                                string u = "";
                                if(!w[0].Equals(Program.LClient.strUserName))
                                    u = w[0];
                                else if(!w[1].Equals(Program.LClient.strUserName))
                                    u = w[1];
                                else
                                    u = w[0];
                                r = getUserRun(u, "<" + w[0] + ">" + w[1] + ": ");
                                Program.TraceWarning("#WHISPER FROM " + u + " : " + chat);
                                r.ToolTip = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString() + "\nClick here to whisper back";
                                b = Brushes.Orange;
                                r.Foreground = b;
                                p.Inlines.Add(new Italic(r));
                                break;
                            case LobbyClient.LobbyChatTypes.Error:
                                r = new Run("!" + user + ": ");
                                r.ToolTip = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString();
                                b = Brushes.Red;
                                r.Foreground = b;
                                r.Cursor = Cursors.Hand;
                                r.Background = Brushes.White;
                                p.Inlines.Add(new Bold(r));
                                break;
                        }
                        if(chat.Contains("\n"))
                        {
                            String[] lines = chat.Split(new char[1] { '\n' });
                            foreach(String line in lines)
                            {
                                String[] words = line.Split(new char[1] { ' ' });
                                foreach(String word in words)
                                {
                                    Inline inn = StringToRun(word, type);

                                    if(inn != null)
                                        p.Inlines.Add(inn);
                                    p.Inlines.Add(new Run(" "));
                                }
                                p.Inlines.Add(new Run("\n"));
                            }
                        }
                        else
                        {
                            String[] words = chat.Split(new char[1] { ' ' });
                            foreach(String word in words)
                            {
                                Inline inn = StringToRun(word, type);

                                if(inn != null)
                                    p.Inlines.Add(inn);
                                p.Inlines.Add(new Run(" "));
                            }
                        }
                        rtbChat.Document.Blocks.Add(p);

                        if(rtbatbottom)
                        {
                            rtbChat.ScrollToEnd();
                        }
                        if(Settings.Default.LobbySound && !Program.lwLobbyWindow.IsActive)
                        {
                            System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.click);
                            sp.Play();
                        }
                    }
                )
            );
        }
示例#34
0
        private void LClient_eUserEvent(LobbyClient.User user, bool Connected)
        {
            System.Threading.Thread thread = new System.Threading.Thread
            (
                new System.Threading.ThreadStart
                (
                    delegate()
                    {
                        rtbChat.Dispatcher.Invoke
                        (
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action
                            (
                                delegate()
                                {
                                    if(rtbChat == null)
                                        return;
                                    if(Connected)
                                    {
                                        if(!user.Username.Equals(""))
                                        {
                                            LClient_eLobbyChat(LobbyClient.LobbyChatTypes.System, "SYSTEM", user.Username + " joined the lobby.", false);
                                            if(Settings.Default.LobbySound)
                                            {
                                                System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.logon);
                                                sp.Play();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if(!user.Username.Equals(""))
                                        {
                                            LClient_eLobbyChat(LobbyClient.LobbyChatTypes.System, "SYSTEM", user.Username + " left the lobby.", false);
                                            if(Settings.Default.LobbySound)
                                            {
                                                System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.logoff);
                                                sp.Play();
                                            }
                                        }
                                    }
                                    Update_Online_Users();
                                }
                            )
                        );
                    }
                )
            );

            thread.Start();
        }
示例#35
0
        private void LClient_eUserStatusChanged(LobbyClient.User user, PlayerStatus status)
        {
            System.Threading.Thread thread = new System.Threading.Thread
             (
                 new System.Threading.ThreadStart
                 (
                     delegate()
                     {
                         rtbChat.Dispatcher.Invoke
                         (
                             System.Windows.Threading.DispatcherPriority.Normal,
                             new Action
                             (
                                 delegate()
                                 {
                                     Update_Online_Users();
                                 }
                             )
                         );
                     }
                 )
             );

            thread.Start();
        }
 void OnLoginAccepted(object sender, LobbyClient.Legacy.TasEventArgs e)
 {
     var tas = (LobbyClient.Legacy.TasClient)sender;
     foreach (var chan in channels) if (!tas.JoinedChannels.ContainsKey(chan)) tas.JoinChannel(chan);
 }
示例#37
0
 public Inline StringToRun(String s, LobbyClient.LobbyChatTypes type)
 {
     Brush b;
     Inline ret = null;
     String strUrlRegex = "(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))";
     Regex reg = new Regex(strUrlRegex);
     s = s.Trim();
     if(type == LobbyClient.LobbyChatTypes.System || type == LobbyClient.LobbyChatTypes.Error)
         b = Brushes.Gray;
     else
         b = Brushes.Black;
     Inline r = new Run(s);
     if(reg.IsMatch(s))
     {
         b = Brushes.LightBlue;
         Hyperlink h = new Hyperlink(r);
         h.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(h_RequestNavigate);
         try
         {
             h.NavigateUri = new Uri(s);
         }
         catch(UriFormatException e)
         {
             s = "http://" + s;
             try
             {
                 h.NavigateUri = new Uri(s);
             }
             catch(Exception ex)
             {
                 r.Foreground = b;
                 System.Windows.Documents.Underline ul = new Underline(r);
             }
         }
         ret = h;
     }
     else
     {
         if(s.Equals(Program.LClient.strUserName))
         {
             b = Brushes.Blue;
             ret = new Bold(r);
         }
         else
         {
             Boolean fUser = false;
             foreach(LobbyClient.User u in Program.LClient.OnlineUsers)
             {
                 if(u.Username == s)
                 {
                     b = Brushes.LightGreen;
                     ret = new Bold(r);
                     ret.ToolTip = "Click to whisper";
                     r.Cursor = Cursors.Hand;
                     r.Background = Brushes.White;
                     r.MouseEnter += delegate(object sender, MouseEventArgs e)
                     {
                         r.Background = new RadialGradientBrush(Colors.DarkGray, Colors.WhiteSmoke);
                     };
                     r.MouseLeave += delegate(object sender, MouseEventArgs e)
                     {
                         r.Background = Brushes.White;
                     };
                     r.MouseUp += delegate(object sender, MouseButtonEventArgs e)
                     {
                         tbMess.Text = "/w " + s + " ";
                         tbMess.Focus();
                     };
                     fUser = true;
                     break;
                 }
             }
             if(!fUser)
             {
                 ret = new Run(s);
             }
         }
     }
     ret.Foreground = b;
     return ret;
 }