private static void ConnectUser(User UserObj, IUserConnection userConnection) { UserObj.Logon = DateTime.UtcNow; UserObj.Room = Server.LoginRoom; UserObj.Room.Users.Add(UserObj); Server.ClientList.Add(UserObj); List<User> WriteAllButUsers = new List<User>(); Server.ClientList.ForEach(delegate(User currentUser) { if(currentUser.Ignores.HasFlag(User.Ignore.Logons) || currentUser.Ignores.HasFlag(User.Ignore.All)) { WriteAllButUsers.Add(currentUser); } }); Server.CommandList.ForEach(delegate(ICommand command) { if(command.Name.Equals("look")) { UserInput newInput = new UserInput(UserObj, "look"); command.Run(newInput); } }); Server.WriteAllBut("[Entering is: " + UserObj.Name + " " + UserObj.Desc + " ] \n", WriteAllButUsers); }
public UserInput(User CurrentUser, string CommandInput) { this.Input = ""; //remove the "." before running command this.CommandInput = CommandInput; if(CommandInput.Length > 0) { this.Input = CommandInput.Remove(0,1); } //string userCommandText = CommandInput.Remove(0,1); this.Args = (String.IsNullOrEmpty(this.Input)) ? new String[] { ""} : this.Input.Split(' '); this.InputStart = (String.IsNullOrEmpty(this.Input)) ? 0 : this.Input.IndexOf(' '); this.InputStart = ( this.InputStart>= 0) ? this.InputStart : 0; //make sure the index is above 0 this.Message = this.Input.Remove(0, this.InputStart).Trim(); this.User = CurrentUser; }
static void ws_NewSessionConnected(WebSocketSession session) { WebSocketUserCommunication UserConnection = new WebSocketUserCommunication(session); Random userNamer = new Random(); int userNumber = userNamer.Next(0, 999); User UserObj = new User(new List<IUserConnection>() { UserConnection }, userNumber); ConnectUser(UserObj, UserConnection); }
private static void ListenForClients() { tcpListener.Start(); while (true) { //should talker move to async? TcpClient client = tcpListener.AcceptTcpClient(); Random userNamer = new Random(); int userNumber = userNamer.Next(0, 300); TcpUserCommunication tcpClient = new TcpUserCommunication(client); User UserObj = new User(new List<IUserConnection>() { tcpClient }, userNumber); tcpClient.User = UserObj; AsyncCallback callBack = new AsyncCallback(ProcessUserRead); client.GetStream().BeginRead(tcpClient.readingBytes, 0, 4096, callBack, tcpClient); ConnectUser(UserObj, tcpClient); } }
private static void HandleClientCommunication(User userObj, string userInput) { UserInput CurrentInput = new UserInput(userObj, userInput); if (userInput.StartsWith(".")) { if (userInput.Trim().Length == 1) { userObj.LastCommand.Run(userObj.LastInput); return; } //TODO: need to check partial input as well ICommand CurrentCommand = Server.CommandList.Find(x => x.Name.Equals(CurrentInput.Args [0].ToLower())); if (CurrentCommand != null) { userObj.LastCommand = CurrentCommand; userObj.LastInput = CurrentInput; CurrentCommand.Run(CurrentInput); } else { userObj.WriteLine("Unknown command."); } } else { //TODO: setup default command thing.. Server.DefaultCommand.Run(CurrentInput); } }
public UserCommuncationBuffer(DateTime send, string message, User from) { this.Send = send; this.Message = message; this.From = from; }
public User JoinUser(User joinUser) { this.Age = joinUser.Age; this.Desc = joinUser.Desc; this.Email = joinUser.Email; this.Gender = joinUser.Gender; this.InMsg = joinUser.InMsg; this.Ignores = joinUser.Ignores; this.LastCommand = joinUser.LastCommand; this.LastInput = joinUser.LastInput; this.Logon = joinUser.Logon; this.Name = joinUser.Name; this.OutMsg = joinUser.OutMsg; //TODO: notify room if different? if (this.Room != joinUser.Room) { this.ChangeRoom(joinUser.Room); } this.TellBuffer = joinUser.TellBuffer; this.TotalLogins = joinUser.TotalLogins; List<IUserConnection> userConnectionList = new List<IUserConnection>(); userConnectionList.AddRange(this.Connections); userConnectionList.AddRange(joinUser.Connections); foreach (IUserConnection currentConnection in userConnectionList) { currentConnection.User = this; } this.Connections = new ReadOnlyCollection<IUserConnection>(userConnectionList); return joinUser; }