Beispiel #1
0
 private void OnClientDisconnect(ClientConnection client, string reason)
 {
     if (reason == null)
     {
         Server.Broadcast("<Server> " + Nicks[client.ClientID] + " has quit.");
     }
     else
     {
         string addition = reason.EndsWith(".") ? "" : ".";
         Server.Broadcast("<Server> " + Nicks[client.ClientID] + " has quit. Reason: " + reason + addition);
     }
     Nicks.Remove(client.ClientID);
 }
Beispiel #2
0
 private void ProcessMessage(ClientConnection client, string line)
 {
     Server.Broadcast("<" + Nicks[client.ClientID] + "> " + line);
 }
Beispiel #3
0
 private void OnClientConnection(ClientConnection client)
 {
     Nicks.Add(client.ClientID, client.Host);
     //client.SendData("<Server> Welcome! Please choose a nickname using the /nick <nickname> command.");
 }
Beispiel #4
0
 private void ProcessCommand(ClientConnection client, string[] args)
 {
     if (args.Length < 1) return;
     if (args.Length >= 2 && args[0].ToUpper().Equals("NICK"))
     {
         if(args[1].Equals("") || args[1].Equals(" ") || args[1].Equals(null))
         {
             client.SendData("<Server> Invalid characters (Spaces?) in username. Allowed characters are a-z, A-Z, 0-9, _, and -");
             client.SendData("The nick you tried to set is: <" + args[1] + ">");
         }
         if (args[1].ToLower().Equals("server") || args[1].ToLower().Contains("admin"))
         {
             client.SendData("<Server> That nick is reserved.");
         }
         else if (Nicks.ContainsValue(args[1]))
         {
             client.SendData("<Server> That nick is already taken.");
         }
         else if (Regex.IsMatch(args[1], @"^[a-zA-Z0-9_\-]"))
         {
             Server.Broadcast("<Server> " + Nicks[client.ClientID] + " changed nick to " + args[1] + ".");
             Nicks[client.ClientID] = args[1];
         }
         else
         {
             client.SendData("<Server> Invalid characters in username. Allowed characters are a-z, A-Z, 0-9, _, and -");
         }
     }
     else if (args[0].ToUpper().Equals("DISCONNECT"))
     {
         if (args.Length > 1)
         {
             string quitReason = "";
             for (int i = 1; i < args.Length; i++)
             {
                 quitReason += args[i] + " ";
             }
             client.Disconnect(quitReason);
         }
         else
         {
             client.Disconnect(null);
         }
     }
 }
Beispiel #5
0
 private void OnClientInput(ClientConnection client, string line)
 {
     if (line.StartsWith("/"))
     {
         ProcessCommand(client, line.Substring(1).Split(new char[] {' '}));
     }
     else
     {
         ProcessMessage(client, line);
     }
 }
Beispiel #6
0
 private void WaitForIncomingConnections()
 {
     Log("Listening for new connections.");
     while (true)
     {
         ClientConnection connection = new ClientConnection(this);
         connection.Connect(Listener.AcceptTcpClient());
         Log("Client connected at " + connection.Host);
         ClientConnections.Add(connection);
         if (OnClientConnection != null)
         {
             OnClientConnection(connection);
         }
     }
 }
Beispiel #7
0
        internal void RemoveClientConnection(ClientConnection connection, string reason)
        {
            if (!connection.Client.Connected)
            {
                ClientConnections.Remove(connection);
                if (OnClientDisconnect != null)
                {
                    OnClientDisconnect(connection, reason);
                }

                Log("Client disconnected");
            }
        }
Beispiel #8
0
 internal void ProcessIncominData(string data, ClientConnection connection)
 {
     if (data == null)
     {
         connection.Disconnect();
     }
     else
     {
         if (OnClientInputEvent != null)
         {
             OnClientInputEvent(connection, data);
         }
     }
 }