private void CommandReceived(object sender, CommandEventArgs e) { //When a client connects to the server sends a 'ClientLoginInform' command with a MetaData in this format : //"RemoteClientIP:RemoteClientName". With this information we should set the name of ClientManager and then //Send the command to all other remote clients. if (e.Command.CommandType == CommandType.ClientLoginInform) { SetManagerName(e.Command.SenderIP, e.Command.MetaData); } //If the client asked for existance of a name,answer to it's question. if (e.Command.CommandType == CommandType.IsNameExists) { var isExixsts = IsNameExists(e.Command.SenderIP, e.Command.MetaData); SendExistanceCommand(e.Command.SenderIP, isExixsts); return; } //If the client asked for list of a logged in clients,replay to it's request. if (e.Command.CommandType == CommandType.SendClientList) { SendClientListToNewClient(e.Command.SenderIP); return; } if (e.Command.Target.Equals(IPAddress.Broadcast)) BroadCastCommand(e.Command); else SendCommandToTarget(e.Command); }
/// <summary> /// Occurs when a command received from a remote client. /// </summary> /// <param name="e">Received command.</param> protected virtual void OnCommandReceived(CommandEventArgs e) { if (CommandReceived != null) CommandReceived(this, e); }