// Creates a new chat server and invites requested users to server // First element in requested users is the sending users id private static void OpenNewChatServer(PacketHeader header, Connection connection, string[] requestedUsers) { // Open a new chat server and connect current user ChatServer newServer = new ChatServer(); chatServers[newServer.chatServerId] = newServer; ConnectionInfo requestingUser = connections[int.Parse(requestedUsers[0])]; newServer.connectUser(requestingUser); connection.SendObject("chatServerOpened", newServer.chatServerId); // Sends a request to each user if they would like to connect to the chat server foreach (KeyValuePair <int, ConnectionInfo> connectedUser in connections) { for (int i = 1; i < requestedUsers.Count(); i++) { if (requestedUsers[i] == connectedUser.Value.username) { connectedUser.Value.connection.SendObject("userConnectionRequest", newServer.chatServerId + "|User " + requestingUser.username + " would like to chat. Accept?"); } } } }
public void joinServer(ChatServer cs) { cs.connectUser(this); connectedServers.Add(cs.chatServerId); }