void SendGameWorldChanges(params Helpers.User[] users) { try { Helpers.TcpGameWorld add = new Helpers.TcpGameWorld(CompareWorlds(true), true); Helpers.TcpGameWorld remove = new Helpers.TcpGameWorld(CompareWorlds(false), false); Logging.Info("[Debug] SendGameWorldChanges() => Add: " + add.Serialize().Length + " Remove: " + remove.Serialize().Length); if (users.Length < 1) { //If users aren't set, it will send it to all users connected to the server foreach (Helpers.User u in Networking.Server.Users.ToArray()) { Networking.Server.Send(u.ID, add); Networking.Server.Send(u.ID, remove); } return; } foreach (Helpers.User user in users) { Networking.Server.Send(user.ID, add); Networking.Server.Send(user.ID, remove); } } catch (Exception ex) { Logging.Error(ex.Message, ex.StackTrace); } }
public void UpdateWorld(World servercontent, bool adds) { if (adds) { Logging.Info("[GameWorld] Will add new content to the GameWorld"); Helpers.TcpGameWorld gwc = new Helpers.TcpGameWorld(servercontent, true); Networking.Client.Send(gwc); } else { Logging.Info("[GameWorld] Will remove content from the GameWorld"); Helpers.TcpGameWorld gwc = new Helpers.TcpGameWorld(servercontent, false); Networking.Client.Send(gwc); } }
private void UpdateClients(object sender, EventArgs e) { if (oldworld != null) { Logging.Info("[GameWorld] Updating GameWorld"); SendGameWorldChanges(); } else { Logging.Info("[GameWorld] Sending GameWorld because oldworld is null!"); Helpers.TcpGameWorld gwm = new Helpers.TcpGameWorld(world, true); Networking.Server.Send(gwm); } oldworld = world; //Set oldworld to world to see if anything did change }