public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { var roomName = JoinArg(0); if (!Helper.VerifyName(roomName)) { info.SendChatMessage("Invalid room name.", Helper.ServerErrorColor); return; } if (!RoomManager.Exists(roomName)) { RoomManager.CreateRoom(roomName, socket); } else { if (room != RoomManager.Rooms[roomName]) { RoomManager.AddUserToRoom(socket, roomName); } else { info.SendChatMessage("You're already in this room.", Helper.ServerErrorColor); } } Console.WriteLine(info.Name + "(" + Helper.IPString(socket) + ") changed room to " + roomName + "."); }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { var oldName = info.Name; string newName = Helper.GetUserName(JoinArg(), info.GetRoom()); if (!Helper.VerifyName(newName)) { info.SendChatMessage("Invalid name.", Helper.ServerErrorColor); return; } if (oldName == newName) { info.SendChatMessage("You already have that name.", Helper.ServerErrorColor); return; } info.Name = newName; info.SendSetName(newName, room == null, newName == JoinArg()); // permanent = if true, the client will know this name is permanent, and not a rename. different from what's expected. (example: rename to Name, becomes Name(1)) if (room != null) { room.SendChatMessageToAll(oldName + " changed name to " + newName + "."); } else { info.SendChatMessage("Name set to " + newName + "."); } }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (room.IsOwner(socket)) { var targetUser = room.GetUser(JoinArg()); if (targetUser != null) { if (targetUser != socket) { room.KickUser(targetUser); } else { info.SendChatMessage("You can't kick yourself.", Helper.ServerErrorColor); } } else { info.SendChatMessage("There's no user with that name in the room.", Helper.ServerErrorColor); } } else { info.SendChatMessage("You need to be the owner to use this command.", Helper.ServerErrorColor); } }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (Args.Length > 0) { var command = CommandManager.GetCommand(Args[0].ToLower()); if (command != null) { var capitalized = command.Command.Capitalize(); socket.GetInfo().SendChatMessage(capitalized + ": " + command.HelpString); socket.GetInfo().SendChatMessage("Minimum required arguments: " + command.MinimumArgCount); } else { socket.GetInfo().SendChatMessage("There is no command with this name.", Helper.ServerErrorColor); } } else { string result = "-- Commands --\n"; foreach (var command in CommandManager.GetCommands()) { result += "• " + command.Command.Capitalize() + ": " + command.HelpString + "\n"; } result += "-- End of commands --"; info.SendChatMessage(result); } }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (room != null) { var result = "Users in this room: "; foreach (var user in room.Sockets.OrderBy(socket2 => socket2.GetInfo().Name)) { result += user.GetInfo().Name + ", "; } result = result.Remove(result.LastIndexOf(", ")); info.SendChatMessage(result); } else { info.SendChatMessage("You need to join a room to use this command.", Helper.ServerErrorColor); } }
public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets) { var color = (string)data["color"]; if (Helper.VerifyNameColor(color)) { info.NameColor = color; } else { info.SendChatMessage("\"" + color + "\" is not an accepted color.", Helper.ServerErrorColor); } }
public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets) { var message = (string)data["message"]; if (message.StartsWith("/")) { if (!CommandManager.HandleCommand(message, socket)) { info.SendChatMessage("Unknown command.", Helper.ServerErrorColor); } } else { if (room != null) { room.SendChatMessageToAll(message, info.Name, "#FFF", info.NameColor); } else { info.SendChatMessage("You need to join a room to use the chat. Type /room [room name] to join the room called [room name].", Helper.ServerErrorColor); } } }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (room != null) { if (room.Owner == socket) { var nextOwner = room.GetUser(JoinArg()); if (nextOwner != null) { if (nextOwner != socket) { room.NextOwner = nextOwner; info.SendChatMessage("Next owner is now " + nextOwner.GetInfo().Name + "."); nextOwner.GetInfo().SendChatMessage("You are now the next owner of this room.", Helper.ServerRoomColor); } else { info.SendChatMessage("You are already the owner of this room.", Helper.ServerErrorColor); } } else { info.SendChatMessage("There's no user in this room with that name.", Helper.ServerErrorColor); } } else { info.SendChatMessage("You need to be the owner of the room to use this command.", Helper.ServerErrorColor); } } else { info.SendChatMessage("You need to join a room to use this command.", Helper.ServerErrorColor); } }
public override void HandleCommand(Fleck.IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (room != null) { var videoInfos = room.Playlist.ToArray(); string message = "-- Start of playlist --\n"; for (int i = 0; i < videoInfos.Length; i++) { var videoId = videoInfos[i]; message += "[" + i + "]: " + videoId.VideoID + "\n"; } message += "-- End of playlist --"; info.SendChatMessage(message); } }
public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { var username = JoinArg(); if (room != null) { if (room.IsOwner(socket)) { var targetUser = room.GetUser(username); if (targetUser != null) { if (targetUser != socket) { if (!room.IsPrivileged(targetUser)) { targetUser.GetInfo().SendAndSetPrivileged(true); info.SendChatMessage(targetUser.GetInfo().Name + " is now a privileged user."); } else { targetUser.GetInfo().SendAndSetPrivileged(false); info.SendChatMessage(targetUser.GetInfo().Name + " is no longer a privileged user."); } } else { info.SendChatMessage("You are already privileged by being the owner.", Helper.ServerErrorColor); } } else { info.SendChatMessage("There's no user with that name in this room.", Helper.ServerErrorColor); } } else { info.SendChatMessage("You need to be the owner of the room to use this command.", Helper.ServerErrorColor); } } else { info.SendChatMessage("You need to join a room before using this command.", Helper.ServerErrorColor); } }