Exemplo n.º 1
0
 public virtual void OnEventServerRecieveMessage(ServerCommandEventArgs args)
 {
     if (EventServerRecieveMessage != null)
     {
         EventServerRecieveMessage(this, args);
     }
 }
Exemplo n.º 2
0
 public virtual void OnEventClientDisconnect(ServerCommandEventArgs args)
 {
     if (EventClientDisconnect != null)
     {
         EventClientDisconnect(this, args);
     }
 }
Exemplo n.º 3
0
 public void OnEventClientConnect(object source, ServerCommandEventArgs args)
 {
     //send to a list of clients***
     //args.Message = "A client is connecting to server...";
     //clientConnection.clientName = args.Message;
     SendUserListToClients();
     foreach (ClientHandler client in ClientHandler.clientList)
     {
         SendMessageToClient(client, clientConnection.clientName + " connected to server!");
     }
 }
Exemplo n.º 4
0
        public void OnEventServerSendMessage(object source, ServerCommandEventArgs args)
        {
            Console.WriteLine("Send Message method called");
            // send to a list on clients***

            Console.WriteLine("Message recieved:" + args.Message);
            foreach (ClientHandler client in ClientHandler.clientList)
            {
                SendMessageToClient(client, clientConnection.clientName + ": " + args.Message);
            }
        }
Exemplo n.º 5
0
        public void OnEventClientDisconnect(object source, ServerCommandEventArgs args)
        {
            // args.Message = "A client is disconnecting from server...";
            //notify other users that he left
            ClientHandler.clientList.Remove(clientConnection);
            SendUserListToClients();
            foreach (ClientHandler client in ClientHandler.clientList)
            {
                SendMessageToClient(client, clientConnection.clientName + " disconnected from server :(");
            }

            clientConnection.CloseConnection();
        }
Exemplo n.º 6
0
        public void OnEventServerRecieveMessage(object source, ServerCommandEventArgs args)
        {
            //verify the message
            if (args.Message.StartsWith(CommandSetName))
            {
                if (clientConnection.clientName == null)
                {
                    clientConnection.clientName = args.Message.Substring(CommandSetName.Length).Trim();
                    clientConnection.OnEventClientConnect(new ServerCommandEventArgs()
                    {
                        Message = clientConnection.clientName
                    });
                }
                else
                {
                    if (args.Message.Substring(CommandSetName.Length).Trim() != "")
                    {
                        if (!IsNameTaken(args.Message.Substring(CommandSetName.Length).Trim()))
                        {
                            clientConnection.clientName = args.Message.Substring(CommandSetName.Length).Trim();
                        }
                    }
                }
                SendUserListToClients();

                // clientConnection.OnEventClientConnect(new ServerCommandEventArgs() {Message = clientConnection.clientName});
            }
            else if (args.Message.StartsWith(CommandDisconnect))
            {
                clientConnection.OnEventClientDisconnect(new ServerCommandEventArgs()
                {
                    Message = clientConnection.clientName
                });
            }
            else
            {
                clientConnection.OnEventServerSendMessage(args);
            }
        }