Esempio n. 1
0
 public virtual void OnEventServerRecieveMessage(ServerCommandEventArgs args)
 {
     if (EventServerRecieveMessage != null)
     {
         EventServerRecieveMessage(this, args);
     }
 }
Esempio n. 2
0
 public virtual void OnEventClientDisconnect(ServerCommandEventArgs args)
 {
     if (EventClientDisconnect != null)
     {
         EventClientDisconnect(this, args);
     }
 }
 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!");
     }
 }
        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);
            }
        }
        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();
        }
        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);
            }
        }