Exemple #1
0
        // Connects user to chat server and sends the chat log
        private static void ConnectToChatServer(PacketHeader header, Connection connection, string[] info)
        {
            Console.WriteLine("New user joining chat server: " + int.Parse(info[1]));
            // Get users connection and chat server
            int            userId         = int.Parse(info[0]);
            int            chatId         = int.Parse(info[1]);
            ChatServer     cs             = chatServers[chatId];
            ConnectionInfo userConnection = connections[userId];

            // Connect user to chat server
            userConnection.joinServer(cs);

            // Send user current chat server log
            connection.SendObject("ChatLog", cs.ChatLog);
        }
Exemple #2
0
        // 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?");
                    }
                }
            }
        }
Exemple #3
0
 public void leaveServer(ChatServer cs)
 {
     cs.disconnectUser(this);
     connectedServers.Remove(cs.chatServerId);
 }
Exemple #4
0
 public void joinServer(ChatServer cs)
 {
     cs.connectUser(this);
     connectedServers.Add(cs.chatServerId);
 }