public ChatMessage(ChatType type, int dest, string message) { this.Sender = null; this.Type = type; this.Destination = dest; this.Message = message; }
public ChatMessage(Character sender, ChatType type, int dest, string message) { this.Sender = sender; this.Type = type; this.Destination = dest; this.Message = message; }
public void HandleCommand(Character sender, string command, string[] args) { try { #region Debugging if (command == "testparse") { string argList = ""; foreach (string a in args) argList += a + "|"; string message = String.Format("Command \"{0}\", Args \"{1}\"", command, argList.Trim('|')); context.ChatProcessor.SendServerMessage(message, sender.CharacterId); } #endregion #region Zone Management if (command == "addzone") { if (args.Length > 2) { string name = args[0]; int width = Convert.ToInt32(args[1]); int height = Convert.ToInt32(args[2]); if (context.ZoneManager.AddZone(name, width, height)) context.ChatProcessor.SendServerMessage(String.Format("Zone '{0}' created sucessfully.", name), sender.CharacterId); else context.ChatProcessor.SendServerMessage("Failed to create zone, name must be taken.", sender.CharacterId); } } else if (command == "removezone") { if (args.Length > 0) { int id = Convert.ToInt32(args[0]); Zone zone = context.ZoneManager.GetZone(id); if (zone != null) { if (context.ZoneManager.DeleteZone(id)) context.ChatProcessor.SendServerMessage(String.Format("Zone '{0}' deleted sucessfully.", zone.Name), sender.CharacterId); else context.ChatProcessor.SendServerMessage("Failed to delete zone. Unknown problem.", sender.CharacterId); } else context.ChatProcessor.SendServerMessage("Failed to delete zone. Zone doesn't exist.", sender.CharacterId); } } else if (command == "editzone") { if (args.Length > 3) { int id = Convert.ToInt32(args[0]); Zone zone = context.ZoneManager.GetZone(id); if (zone != null) { string name = args[1]; int width = Convert.ToInt32(args[2]); int height = Convert.ToInt32(args[3]); zone.ChangeZone(name, width, height); context.ChatProcessor.SendServerMessage(String.Format("Zone '{0}' updated sucessfully. ('{1}', {2}x{3}).", id, name, width, height), sender.CharacterId); ServerToClientMessage wm = ServerToClientMessage.CreateMessageSafe(); MessageFormatter.CreateZoneSyncMessage(new Zone[] { zone }, wm); context.ZoneManager.AddMessageToZone(id, wm); ServerToClientMessage.FreeSafe(wm); } else context.ChatProcessor.SendServerMessage("Failed to edit zone. Zone doesn't exist.", sender.CharacterId); } } else if (command == "loadzone") { if (args.Length > 0) { int id = Convert.ToInt32(args[0]); if (!context.ZoneManager.ZoneExists(id)) { Zone zone = context.Dal.LoadZone(id); if (zone != null) { context.ZoneManager.AddZone(zone); context.ChatProcessor.SendServerMessage(String.Format("Zone '{0}' loaded successfully.", zone.Name), sender.CharacterId); } else context.ChatProcessor.SendServerMessage("Failed to load zone. Zone doesn't exist.", sender.CharacterId); } else context.ChatProcessor.SendServerMessage("Failed to load zone. Zone is already loaded.", sender.CharacterId); } } else if (command == "listzones") { context.ChatProcessor.SendServerMessage("Currently loaded zones:", sender.CharacterId); foreach (Zone z in context.ZoneManager.Zones) context.ChatProcessor.SendServerMessage(String.Format("ID:{0}, Name: '{1}', Size: {2}x{3}, Entities: {4}({5}).", z.Id, z.Name, z.Width, z.Height, z.AllEntities.Count, z.Characters.Count), sender.CharacterId); } else if (command == "savezones") { ThreadPool.QueueUserWorkItem(new WaitCallback(context.ZoneManager.SaveAllZones)); context.ChatProcessor.SendServerMessage("Started background zone save..", sender.CharacterId); } #endregion #region Entity Management if (command == "addentity") { if (args.Length > 2) { int type = Convert.ToInt32(args[0]); int x = Convert.ToInt32(args[1]); int y = Convert.ToInt32(args[2]); if (context.GameProcessor.AddEntity(type, sender.Zone, x, y, sender.CharacterId)) context.ChatProcessor.SendServerMessage("Entity added successfully.", sender.CharacterId); else context.ChatProcessor.SendServerMessage("Failed to add entity.", sender.CharacterId); } } else if (command == "removeentity") { if (args.Length > 0) { int id = Convert.ToInt32(args[0]); if (context.GameProcessor.RemoveEntity(id)) context.ChatProcessor.SendServerMessage("Entity removed successfully.", sender.CharacterId); else context.ChatProcessor.SendServerMessage("Failed to remove entity.", sender.CharacterId); } } else if (command == "listentities") { Zone z = context.ZoneManager.GetZone(sender.Zone); context.ChatProcessor.SendServerMessage("Current zone entities:", sender.CharacterId); foreach (Entity e in z.AllEntities) { string entityInfo = string.Format("ID:{0}, Type:{1}, Name:{2}, Zone:{3}, Pos:{4}, Owner:{5}", e.Id, e.TypeId, e.Name, e.Zone, e.Position, e.Owner); context.ChatProcessor.SendServerMessage(entityInfo, sender.CharacterId); } } #endregion if (command == "teleport") { if (args.Length > 2) { int zoneId = Convert.ToInt32(args[0]); int x = Convert.ToInt32(args[1]); int y = Convert.ToInt32(args[2]); if (sender.Zone != zoneId && context.ZoneManager.ZoneExists(zoneId)) { Zone newZone = context.ZoneManager.GetZone(zoneId); context.GameProcessor.Teleport(sender, newZone, x, y); } else { //if (context.ZoneManager.LoadZone(zoneId)) { } context.ChatProcessor.SendServerMessage("That zone doesn't exist, isn't loaded, or you're already in it.", sender.CharacterId); } } } if (command == "help") { context.ChatProcessor.SendServerMessage("Zone Management - addzone, editzone, removezone, loadzone, listzones, savezones.", sender.CharacterId); context.ChatProcessor.SendServerMessage("Entity Management - addentity, removeentity, listentities.", sender.CharacterId); context.ChatProcessor.SendServerMessage("Other - teleport, help.", sender.CharacterId); } } catch (Exception e) { Logger.Output(this, "HandleCommand() exception: {0}, {1}", e.Message, e.StackTrace); } }
private void HandleTeleport(ServerToClientMessage wm) { string[] data = wm.Data.Remove(0, 1).Split('#'); for (int i = 0; i < data.Length; i++) { string key = data[i].Substring(0, 1); string value = data[i].Substring(1, data[i].Length - 1); if (key == "Z") { // id:name:width:height string[] zoneInfo = value.Split(':'); int id = Convert.ToInt32(zoneInfo[0]); if (zoneManager.ZoneExists(id)) { Logger.Output(this, "HandleTeleport() Removing existing zone {0}.", id); zoneManager.RemoveZone(id); } int width = Convert.ToInt32(zoneInfo[2]); int height = Convert.ToInt32(zoneInfo[3]); Zone zone = new Zone(); zone.Initialize(id, zoneInfo[1], width, height); zoneManager.AddZone(zone); int oldZone = playerCharacter.Zone; zoneManager.MoveEntity(playerCharacter, zone); zoneManager.RemoveZone(oldZone); Logger.Output(this, "HandleTeleport() Zone (Id:{0}, Name:{1}, Size:{2}x{3}", id, zoneInfo[1], width, height); } else if (key == "C") { Character character = new Character(value); zoneManager.AddEntity(character); Logger.Output(this, "HandleTeleport() Character (Id:{0}, Name:{1}, Pos:{2}", character.Id, character.Name, character.Position); } else if (key == "E") { int typeId = int.Parse(value.Split('|')[0]); string entityData = value.Split('|')[1]; AddEntityFromFormat(typeId, entityData); Logger.Output(this, "HandleTeleport() Entity sent to parser."); } } }
private void HandleStateChanged(WorldConnection.WorldConnectionState state) { if (connection.State == WorldConnection.WorldConnectionState.Disconnected) { if (!string.IsNullOrWhiteSpace(connection.DisconnectMessage)) Logger.Output(this, connection.DisconnectMessage); HandleCleanup(); } else if (connection.State == WorldConnection.WorldConnectionState.Connected) { } else if (connection.State == WorldConnection.WorldConnectionState.CharacterManagement) { FillCharacterList(); context.Gui.ShowCharSelect(); if (lastState == WorldConnection.WorldConnectionState.InGame) { HandleCleanup(); context.Gui.ClearCharacterInfo(); } } else if (connection.State == WorldConnection.WorldConnectionState.InGame) { context.Gui.HideCharSelect(); playerCharacter = new Character(connection.WorldClient.OwnCharacter); } lastState = state; }
/// <summary> /// Perform any cleanup needed before the next character is started. /// </summary> private void HandleCleanup() { zoneManager.RemoveAllZones(); playerCharacter = null; }
private void AddEntityFromFormat(int typeId, string entityData) { if (typeId == (int)EntityType.Player) { Character character = new Character(entityData); zoneManager.AddEntity(character); Logger.Output(this, "AddEntity() added new character ID {0}.", character.Id); } else if (typeId == (int)EntityType.Unit) { Unit entity = new Unit(entityData); SpriteUnit sprite = new SpriteUnit(entity, TextureManager.Singletone.Get("Windmill")); entity.Tag = sprite; zoneManager.AddEntity(entity); Logger.Output(this, "AddEntity() added new unit ID {0}.", entity.Id); } else if (typeId == (int)EntityType.EnergyStation) { EnergyStation station = new EnergyStation(entityData); SpriteEnergyStation sprite = new SpriteEnergyStation(station, TextureManager.Singletone.Get("EnergyStation")); station.Tag = sprite; zoneManager.AddEntity(station); Logger.Output(this, "AddEntity() added new energy station ID {0}.", station.Id); } else if (typeId == (int)EntityType.EnergyRelay) { EnergyRelay relay = new EnergyRelay(entityData); SpriteEnergyRelay sprite = new SpriteEnergyRelay(relay, TextureManager.Singletone.Get("EnergyRelay")); relay.Tag = sprite; zoneManager.AddEntity(relay); Logger.Output(this, "AddEntity() added new energy relay ID {0}.", relay.Id); } else if (typeId == (int)EntityType.MineralMiner) { MineralMiner miner = new MineralMiner(entityData); SpriteMineralMiner sprite = new SpriteMineralMiner(miner, TextureManager.Singletone.Get("MineralMiner")); miner.Tag = sprite; zoneManager.AddEntity(miner); Logger.Output(this, "AddEntity() added new mineral miner ID {0}.", miner.Id); } else if (typeId == (int)EntityType.BasicLaser) { BasicLaser laser = new BasicLaser(entityData); zoneManager.AddEntity(laser); Logger.Output(this, "AddEntity() added new basic laser ID {0}.", laser.Id); } else if (typeId == (int)EntityType.PulseLaser) { PulseLaser laser = new PulseLaser(entityData); zoneManager.AddEntity(laser); Logger.Output(this, "AddEntity() added new pulse laser ID {0}.", laser.Id); } else if (typeId == (int)EntityType.TacticalLaser) { TacticalLaser laser = new TacticalLaser(entityData); zoneManager.AddEntity(laser); Logger.Output(this, "AddEntity() added new tactical laser ID {0}.", laser.Id); } else if (typeId == (int)EntityType.Asteroid) { Asteroid asteroid = new Asteroid(entityData); SpriteAsteroid sprite = new SpriteAsteroid(asteroid, TextureManager.Singletone.Get("Asteroid1")); asteroid.Tag = sprite; zoneManager.AddEntity(asteroid); Logger.Output(this, "AddEntity() added new asteroid ID {0}.", asteroid.Id); } else { Entity entity = new Entity(entityData); zoneManager.AddEntity(entity); Logger.Output(this, "AddEntity() added unknown entity type ID {0}.", entity.Id); } }
private void StartGame() { playerCharacter = new Character(conn.WorldClient.OwnCharacter); UpdateCharacterStats(); }