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); } }
private void broadcastMsg(AlbotChatMsg msg, short msgType) { foreach (chatUser u in playersInChat) { try{ u.peer.SendMessage(msgType, msg); }catch {} } }
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); }
//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()); }
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(); } }
private void onPlayerleftChat(IIncommingMessage msg) { AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> (); usersList.removePlayerFromList(chatMsg.chatID); }
private void onPlayerJoinedChat(IIncommingMessage msg) { AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> (); usersList.addPlayerToList(chatMsg.username, chatMsg.icon, chatMsg.chatID); }
//Broadcasts the msg to all clients currently in chat private void handleIncomingMsg(IIncommingMessage msg) { AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> (); broadcastMsg(chatMsg, (short)ServerCommProtocl.LobbyChatMsg); }