Exemple #1
0
    private void handleOnJoinedChat(IIncommingMessage msg)
    {
        if (playersInChat.Find(x => x.peer == msg.Peer) != null)
        {
            return;
        }

        //Creates a new chatUser and assigns it a "uniqe" chatId... until we have more users then a long can carry
        //I doubt this will be a problem in the near future....
        AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> ();
        chatUser     newUser = new chatUser(msg.Peer, chatMsg.username, chatMsg.icon, chatIdCounter++);

        //Let everone who already is in chat know!
        AlbotChatMsg joinedMsg = new AlbotChatMsg();

        joinedMsg.icon     = newUser.icon;
        joinedMsg.username = newUser.username;
        joinedMsg.chatID   = newUser.chatID;
        broadcastMsg(joinedMsg, (short)ServerCommProtocl.LobbyPlayerEnter);

        playersInChat.Add(newUser);
        newUser.peer.Disconnected += handleDissconnect;

        //Init the new users chat with all current members, Perhaps this should be one big msg?!
        foreach (chatUser u in playersInChat)
        {
            joinedMsg          = new AlbotChatMsg();
            joinedMsg.icon     = u.icon;
            joinedMsg.username = u.username;
            joinedMsg.chatID   = u.chatID;
            newUser.peer.SendMessage((short)ServerCommProtocl.LobbyPlayerEnter, joinedMsg);
        }
    }
Exemple #2
0
 private void broadcastMsg(AlbotChatMsg msg, short msgType)
 {
     foreach (chatUser u in playersInChat)
     {
         try{
             u.peer.SendMessage(msgType, msg);
         }catch {}
     }
 }
Exemple #3
0
        private void onIncominChatgMsg(IIncommingMessage msg)
        {
            AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> ();
            Text         newMsg  = (Text)Instantiate(MessagePrefab, MessagesList.transform);

            string timeStamp = generateTimeStamp();

            newMsg.text = timeStamp + " " + chatMsg.username + ": " + chatMsg.textMsg;
            newMsg.gameObject.SetActive(true);
        }
Exemple #4
0
    //Can be called from either "handleOnLeftChat()" when a player joines a gameroom or by loging out
    //Or it can be called from the user dissconnecting from the server
    private void handleDissconnect(IPeer peer)
    {
        chatUser user = playersInChat.Find(x => x.peer == peer);

        if (user == null)
        {
            return;
        }

        playersInChat.Remove(user);
        user.peer.Disconnected -= handleDissconnect;

        AlbotChatMsg msg = new AlbotChatMsg();

        msg.chatID = user.chatID;
        broadcastMsg(msg, (short)ServerCommProtocl.LobbyPlayerLeft);
    }
        public virtual void OnSendClick()
        {
            String text = InputField.text;
            if (string.IsNullOrEmpty(text))
                return;

            if (text.Length > maxMessageLenght)
                text = text.Substring(0, maxMessageLenght);

            AlbotChatMsg msg = new AlbotChatMsg();
            msg.textMsg = text;
            msg.username = Msf.Client.Auth.AccountInfo.Username;
            Msf.Connection.SendMessage((short)ServerCommProtocl.LobbyChatMsg, msg);

            InputField.text = "";
            InputField.DeactivateInputField();

            if (_allowFocusOnEnter)
                StartCoroutine(DontAllowFocusOnEnter());
        }
Exemple #6
0
        private void onUiStateChanged(ClientUIStates state)
        {
            bool exitedChat = false, enteredChat = false;

            if (state == ClientUIStates.GameLobby || state == ClientUIStates.PreGame)
            {
                if (isCurrentlyInChat == false)
                {
                    enteredChat       = true;
                    isCurrentlyInChat = true;
                }
            }
            else if (isCurrentlyInChat)
            {
                exitedChat        = true;
                isCurrentlyInChat = false;
            }

            AccountInfoPacket currentAcountInfo = ClientUIOverlord.getCurrentAcountInfo();
            AlbotChatMsg      msg = new AlbotChatMsg()
            {
                icon = int.Parse(currentAcountInfo.Properties [AlbotDictKeys.icon]), username = currentAcountInfo.Username
            };

            if (enteredChat)
            {
                for (int i = MessagesList.transform.childCount; i > 1; i--)
                {
                    Destroy(MessagesList.transform.GetChild(i - 1).gameObject);
                }

                Msf.Connection.SendMessage((short)ServerCommProtocl.LobbyPlayerEnter, msg);
            }
            else if (exitedChat)
            {
                Msf.Connection.SendMessage((short)ServerCommProtocl.LobbyPlayerLeft, msg);
                clearList();
            }
        }
Exemple #7
0
        private void onPlayerleftChat(IIncommingMessage msg)
        {
            AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> ();

            usersList.removePlayerFromList(chatMsg.chatID);
        }
Exemple #8
0
        private void onPlayerJoinedChat(IIncommingMessage msg)
        {
            AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> ();

            usersList.addPlayerToList(chatMsg.username, chatMsg.icon, chatMsg.chatID);
        }
Exemple #9
0
    //Broadcasts the msg to all clients currently in chat
    private void handleIncomingMsg(IIncommingMessage msg)
    {
        AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> ();

        broadcastMsg(chatMsg, (short)ServerCommProtocl.LobbyChatMsg);
    }