private static void ProcessSystemConstructionModules(SolarSystem system) { bool SendUpdate = GalaxyServer.Millis - system.LastStateUpdate >= SolarSystem.UPDATE_RATE; for (int i = system.ConstructionModules.Count - 1; i >= 0; i--) { ConstructionModule c = system.ConstructionModules[i]; if (c.UpdateStateAndCheckIfDone(GalaxyServer.Millis)) { //If we are done, remove it and replace with a station module system.ConstructionModules.RemoveAt(i); system.StationModules.Add(c.ResultingStationModule); ConstructionMessage cm = new ConstructionMessage(); cm.TimeRemaining = 0; cm.Guid = c.Guid; cm.Start = false; foreach (Client client in system.Clients) { GalaxyServer.AddToSendQueue(client, cm); } } else if (SendUpdate) { ConstructionMessage cm = new ConstructionMessage(); cm.TimeRemaining = c.BuildTimeRemaining; cm.Guid = c.Guid; cm.Start = false; foreach (Client client in system.Clients) { } } } }
public void HandleMessage(DropOutOfWarpMessage msg, object extra) { Client client = (Client)extra; Player player = client.Player; if (!player.InWarp) { Console.WriteLine("Drop out of warp msg received when not in warp"); return; } SolarSystem system; //First see if system is loaded in memory already if (!LoadedSystems.TryGetValue(msg.SystemKey, out system)) { Sector sector = new Sector(msg.SectorCoord); //If not check the data store system = DataLayer.GetSystem(msg.SystemKey); //If not, generate the system if (system == null) { system = sector.GenerateSystem(msg.SystemIndex); system.ParentSector = sector; system.Generate(); DataLayer.AddSystem(system); Console.WriteLine("System Generated and Added to Redis"); } else { Console.WriteLine("System Loaded From Reids"); } system.ParentSector = sector; system.Clients = new LinkedList <object>(); } double distance = Vector3.Distance(player.Pos, system.Pos * Galaxy.EXPAND_FACTOR); Console.WriteLine("Distance:" + distance); //give some wiggle room since server/client will not be perfectly in sync if (system != null && distance <= Simulator.WARP_DISTANCE_THRESHOLD * 2) { player.Pos = SYSTEM_START_POS; MoveClientToSystem(client, system); msg.Pos = player.Pos; msg.Rotation = player.Rotation; msg.System = system; GalaxyServer.AddToSendQueue(client, msg); return; } //todo else send some sort of nope msg? }
private static void SendStateUpdate(Client client) { if (GalaxyServer.Millis - client.LastSend > client.ClientSendRate) { Player player = client.Player; PlayerStateMessage pState = new PlayerStateMessage(); pState.PlayerPos = player.Pos; pState.Rotation = player.Rotation; pState.Throttle = player.Throttle; pState.Seq = player.Seq; GalaxyServer.AddToSendQueue(client, pState); player.Seq++; client.LastSend = GalaxyServer.Millis; } }
public void HandleMessage(ConstructionMessage msg, object extra = null) { Client client = (Client)extra; Player player = client.Player; Assembly a = typeof(StationModule).Assembly; StationModule sm = (StationModule)Activator.CreateInstance(a.GetType("GalaxyShared." + msg.ClassName)); sm.SetDataFromJSON(); if (sm.CanBuild(player)) { Vector3 pos = player.Pos + Vector3.Transform(Vector3.Forward * 3, player.Rotation); ConstructionModule cm = new ConstructionModule(GalaxyServer.Millis, pos, player.Rotation, new Dock()); player.SolarSystem.ConstructionModules.Add(cm); msg.TimeRemaining = cm.BuildTimeRemaining; msg.Guid = cm.Guid; msg.ResourcesNeeded = sm.BuildRequirements; GalaxyServer.AddToSendQueue(client, msg); } }
public void HandleMessage(LoginMessage msg, object extra) { Client client = (Client)extra; Console.WriteLine("HandleLoginMessage"); LoginMessage login = DataLayer.GetLogin(msg.UserName); if (login.UserName != null && login.Password == msg.Password) { Console.WriteLine("User " + login.UserName + " logged in"); InitiateLogin(msg.UserName, client); } else { LoginResultMessage m; m.success = false; GalaxyServer.AddToSendQueue(client, m); } }
public void HandleMessage(NewUserMessage msg, object extra) { Client client = (Client)extra; Console.WriteLine("HandleNewUserMessage"); NewUserResultMessage m; LoginMessage login; login.UserName = msg.UserName; login.Password = msg.Password; if (DataLayer.CreateNewLogin(msg.UserName, msg.Password)) { InitiateLogin(msg.UserName, client); } else { m.success = false; GalaxyServer.AddToSendQueue(client, m); } }
public static void AsteroidMining(Client client, Player player) { List <Asteroid> asteroids = player.SolarSystem.Asteroids; Asteroid hit = null; Vector3 pos = player.Pos; asteroids.Sort(new AsteroidComparer(pos)); int count = 0; foreach (Asteroid a in asteroids) { Ray ray = new Ray(pos, Vector3.Transform(Vector3.Forward, player.Rotation)); BoundingSphere sphere = new BoundingSphere(a.Pos, a.Size * Asteroid.SERVER_SIZE_MULTIPLIER); double? result = ray.Intersects(sphere); if (result != null) { hit = a; break; } count++; } Console.WriteLine("Count:" + count); if (hit != null) { hit.Remaining -= player.Ship.MiningLaserPower; player.Ship.AddCargo(new Item(ItemType.IronOre, player.Ship.MiningLaserPower)); Console.WriteLine("hit!:" + hit.Remaining); // GalaxyServer.AddToSendQueue(client, hit); MiningMessage miningState = new MiningMessage(); miningState.Add = true; miningState.Item = new Item(ItemType.IronOre, player.Ship.MiningLaserPower); miningState.AsteroidHash = hit.Hash; miningState.Remaining = hit.Remaining; GalaxyServer.AddToSendQueue(client, miningState); if (hit.Remaining <= 0) { asteroids.Remove(hit); } DataLayer.AddSystem(player.SolarSystem); } }
public void HandleMessage(GoToWarpMessage msg, object extra) { Client client = (Client)extra; msg.Rotation = client.Player.Rotation; Vector3 systemPos = client.Player.SolarSystem.Pos; Vector3 startPos = new Vector3(systemPos.X * Galaxy.EXPAND_FACTOR, systemPos.Y * Galaxy.EXPAND_FACTOR, systemPos.Z * Galaxy.EXPAND_FACTOR); startPos += Vector3.Transform(Vector3.Forward * .3f, client.Player.Rotation); client.Player.Pos = startPos; //client has left, clear em out SolarSystem system = client.Player.SolarSystem; MoveClientToWarp(client); msg.Pos = client.Player.Pos; GalaxyServer.AddToSendQueue(client, msg); }
public static void InitiateLogin(string username, Client client) { Console.WriteLine("InitiateLogin"); //todo - this commented out for testing //Player player = DataLayer.GetGalaxyPlayer(username); Player player = null; Console.WriteLine("Attempted to get GalaxyPlayer"); //new player case if (player == null) { player = new Player(username); DataLayer.UpdateGalaxyPlayer(player); Console.WriteLine("New player created and saved to db"); } Console.WriteLine("About to send player data"); client.Player = player; ClientsInWarp.AddLast(client); GalaxyServer.AddToSendQueue(client, player); Console.WriteLine("Player Data Sent"); }
public static void Main(string[] args) { Galaxy.Init(); GalaxyServer server = new GalaxyServer(); }