public string Receive() { try { while (true) { byte[] recievedMessage = new byte[5000]; stream.Read(recievedMessage, 0, recievedMessage.Length); string messageString = Encoding.ASCII.GetString(recievedMessage); if (messageString.Substring(0, 2) != ">>") { CurrentChatroom.EnqueueMessage(new Message(this, recievedMessage, CurrentChatroom.Name)); } else { return(messageString.Trim().Trim('\0')); } } } catch (IOException) { Server.CloseClient(this); return(""); } }
public void ChangeChatroom(Chatroom chatroom) { if (CurrentChatroom != null) { CurrentChatroom.RemoveUser(UserName); } CurrentChatroom = chatroom; Send($"Welcome to the {CurrentChatroom.Name} chatroom. To change rooms enter '>>' or enter '>>' + the name of the room, for example, '>>Main' to move to the Main chatroom.\n"); CurrentChatroom.AddUser(UserName, this); }
public void Start() { Send(UserName + " welcome to the chat server.\n"); ChatroomMenu(); string input = ""; do { input = Receive(); if (input.Length >= 2 && input.Substring(0, 2) == ">>") { ChatroomMenu(input.Substring(2)); } } while (input != ""); CurrentChatroom.RemoveUser(UserName); }
public void ChangeRoom(Room newRoom) { StartCoroutine(PlaySoundForSeconds(moveSFX, backgroundTransitionTime / 2f)); currentRoom = newRoom; background.ChangeBackground(newRoom, backgroundTransitionTime); visibleCharacters.HideCharacters(); // Chatroom stuff if (CurrentChatroom != null) { CurrentChatroom.Leave(); } CurrentChatroom = newRoom.GetComponent <Chatroom>(); if (CurrentChatroom != null) { CurrentChatroom.Enter(); } }