Пример #1
0
 public void Parse(ServerUpdate serverUpdate, int offsetX, int offsetY, int offsetZ)
 {
     for (uint x = 0; x < Frame1.Length; x++)
     {
         byte[] colors     = BitConverter.GetBytes(Frame1[x][3]); //3=red 2=green 1=blue 0=alpha
         var    blockDelta = new ServerUpdate.BlockDelta()
         {
             position = new IntVector()
             {
                 x = (int)(Frame1[x][0] + offsetX),
                 y = (int)(Frame1[x][2] + offsetY),
                 z = (int)(Frame1[x][1] + offsetZ)
             },
             color = new ByteVector()
             {
                 x = colors[3],
                 y = colors[2],
                 z = colors[1]
             },
             type    = (colors[3] == 0 && colors[2] == 0 && colors[1] == 0xFF) ? BlockType.Liquid : BlockType.Solid,
             unknown = 0
         };
         serverUpdate.blockDeltas.Add(blockDelta);
     }
 }
Пример #2
0
        public void TeleportPlayer(Player player, long x, long y, long z)
        {
            var staticEntity = new ServerUpdate.StaticEntity {
                chunkX   = BitConverter.ToInt32(BitConverter.GetBytes(x), 3),
                chunkY   = BitConverter.ToInt32(BitConverter.GetBytes(y), 3),
                id       = 0,
                type     = 18,
                position = new Resources.Utilities.LongVector()
                {
                    x = x,
                    y = y,
                    z = z,
                },
                rotation = 2,
                time     = 1000,
                guid     = player.entityData.guid
            };

            var serverUpdate = new ServerUpdate();

            serverUpdate.statics.Add(staticEntity);
            serverUpdate.Write(player.writer, true);
            staticEntity.guid = 0;
            serverUpdate.Write(player.writer, true);
        }
Пример #3
0
        public void TicketsUpdated(ServerUpdate su)
        {
            if (su == null || su.nextTicket == null)
            {
                return;
            }

            TerminalTicket ticket = su.nextTicket;

            this.Dispatcher.Invoke(() =>
            {
                if (ticket.type == 0)
                {
                    Row1_Ticket.Text   = "A" + ticket.number;
                    Row1_Terminal.Text = "" + ticket.clientId;
                }
                else if (ticket.type == 1)
                {
                    Row2_Ticket.Text   = "B" + ticket.number;
                    Row2_Terminal.Text = "" + ticket.clientId;
                }
                //else if (ticket.type == 3)
                //{
                //    Row3_Ticket.Text = "C" + ticket.number;
                //    Row3_Terminal.Text = "" + ticket.clientId;
                //}
            });
        }
Пример #4
0
        public ActionResult DownloadRelease(HttpPostedFileBase fileXml)
        {
            try
            {
                var fileName = Path.GetFileName(fileXml.FileName);
                var pathXml  = Path.Combine(_directoryPath + $@"\{fileName}");
                fileXml.SaveAs(pathXml);
                var lastRelease            = _companyUpdateService.ValidateXmlFile(pathXml, $"{User.Name} {User.LastName}");
                var recenteRelease         = _releaseService.GetLatestRelease(lastRelease.ReleaseId).ToList();
                var releaseDistinctCompany = _companyReleaseService.GetReleaseListDownload(recenteRelease.Select(x => x.Id), lastRelease.ServerId);
                recenteRelease = recenteRelease.Where(x => !releaseDistinctCompany.Contains(x.Id)).ToList();
                if (recenteRelease.Any())
                {
                    var companyUpdate = new ServerUpdate
                    {
                        ServerId = lastRelease.ServerId,
                        Update   = lastRelease.Update
                    };
                    byte[] data = CreateRelease(companyUpdate, recenteRelease);
                    Log.Instance.Info($"Iniciando descarga Isolucion_{recenteRelease.Last().Version}.zip");
                    return(File(data, MediaTypeNames.Application.Octet, $@"Isolucion_{recenteRelease.Last().Version}.zip"));
                }
            }
            catch (Exception ex)
            {
                Log.Instance.Error(ex);
            }

            return(RedirectToAction("Index"));
        }
        public void NewListReceived(ServerUpdate update)
        {
            if (update == null)
            {
                window.NewListReceived(null);
                return;
            }

            if (update.nextTicket == null)
            {
                window.NoMoreTicketsAvailable();
                return;
            }

            this.data = update;
            window.NewListReceived(data);

            var currTicket = update.GetCurrentTicket();

            if (currTicket != null)
            {
                string sTicketType = (currTicket.type == 0 ? "A" : "B") + currTicket.number;
                window.UpdateCurrentTicket(sTicketType);
            }
        }
Пример #6
0
    public void AddResourceToHanger(int hangarID, int type, int qte)
    {
        Hangar h = _container._hangars[hangarID];

        ResourceStack stack = null;

        foreach (int id in h.StacksIDs)
        {
            ResourceStack tmp = _container._resourceStacks[id];
            if (tmp.Type == type)
            {
                stack = tmp;
                break;
            }
        }
        if (null == stack)
        {
            stack        = new ResourceStack(_container._resourceStackIDs++);
            stack.Qte    = 0;
            stack.Type   = type;
            stack.Loaded = true;
            _container._resourceStacks.Add(stack.ID, stack);
            h.StacksIDs.Add(stack.ID);
        }

        stack.Qte += qte;

        ServerUpdate update = new ServerUpdate();

        update.stacks.Add(stack);
        update.hangars.Add(h);
        _manager.SendServerUpdate(update);
    }
        public MainWindowController(MainWindow window, string ip)
        {
            this.window = window;

            data = new ServerUpdate();
            InitializeServer(ip);
        }
Пример #8
0
 public ActionResult DownloadFirstRelease()
 {
     try
     {
         var recenteRelease         = _releaseService.GetLatestRelease(Guid.Empty).ToList();
         var releaseDistinctCompany = _companyReleaseService.GetReleaseListDownload(recenteRelease.Select(x => x.Id), User.CompanyId);
         recenteRelease = recenteRelease.Where(x => !releaseDistinctCompany.Contains(x.Id)).ToList();
         if (recenteRelease.Any())
         {
             var companyUpdate = new ServerUpdate
             {
                 ServerId = User.CompanyId,
                 Update   = DateTime.Now
             };
             byte[] data = CreateRelease(companyUpdate, recenteRelease);
             Log.Instance.Info($"Iniciando descarga Isolucion_{recenteRelease.Last().Version}.zip");
             return(File(data, MediaTypeNames.Application.Octet, $@"Isolucion_{recenteRelease.Last().Version}.zip"));
         }
     }
     catch (Exception ex)
     {
         Log.Instance.Error(ex);
     }
     return(RedirectToAction("Index"));
 }
Пример #9
0
 public void UpdateServerInfo(string name, int gamePort, int queryPort, int maxPlayers)
 {
     Name       = name;
     GamePort   = gamePort;
     QueryPort  = queryPort;
     MaxPlayers = maxPlayers;
     ServerUpdate?.Invoke(name, gamePort, queryPort, maxPlayers);
 }
Пример #10
0
        public static void TCP(string command, string parameter, Player player)
        {
            switch (command)
            {
            case "spawn":
                break;

            case "reload_world":
                break;

            case "xp":
                try {
                    int amount = Convert.ToInt32(parameter);

                    var xpDummy = new EntityUpdate()
                    {
                        guid      = 1000,
                        hostility = (byte)Hostility.enemy
                    };
                    xpDummy.Write(player.writer);

                    var kill = new ServerUpdate.Kill()
                    {
                        killer = player.entityData.guid,
                        victim = 1000,
                        xp     = amount
                    };
                    var serverUpdate = new ServerUpdate();
                    serverUpdate.kills.Add(kill);
                    serverUpdate.Write(player.writer, true);
                    break;
                } catch (Exception) {
                    //invalid syntax
                }
                break;

            case "time":
                try {
                    int index  = parameter.IndexOf(":");
                    int hour   = Convert.ToInt32(parameter.Substring(0, index));
                    int minute = Convert.ToInt32(parameter.Substring(index + 1));

                    var time = new Time()
                    {
                        time = (hour * 60 + minute) * 60000
                    };
                    time.Write(player.writer, true);
                } catch (Exception) {
                    //invalid syntax
                }
                break;

            default:
                break;
            }
        }
Пример #11
0
 protected void Fuel(ServerUpdate serverUpdate)
 {
     foreach (int sID in _fleet.ShipIDs)
     {
         Ship ship = _data._ships[sID];
         ship.AddLog("Fueled for X ICU");
         serverUpdate.Add(ship);
     }
     _fleet.FleetParams.Set("currentState", "doneFueling");
 }
Пример #12
0
        public Server Update([FromBody] ServerUpdate server)
        {
            Settings settings = _settingsStore.Load();

            settings.Port      = server.port;
            settings.IsEnabled = server.isEnabled;
            _settingsStore.Save(settings);

            return(Get(server.id));
        }
Пример #13
0
 public void Poison(ServerUpdate poisonTick, int duration)
 {
     if (players.ContainsKey(poisonTick.hits[0].target))
     {
         poisonTick.hits[0].position = players[poisonTick.hits[0].target].entityData.position;
         poisonTick.Broadcast(players, 0);
         if (duration > 0)
         {
             Task.Delay(500).ContinueWith(t => Poison(poisonTick, duration - 500));
         }
     }
 }
Пример #14
0
    protected void StartUndock(ServerUpdate serverUpdate)
    {
        NextUpdateFrame(50);

        foreach (int sID in _fleet.ShipIDs)
        {
            Ship ship = _data._ships[sID];
            ship.Status = "Undocking";
            serverUpdate.Add(ship);
        }
        _fleet.FleetParams.Set("currentState", "undocking");
    }
 public void NewListReceived(ServerUpdate update)
 {
     this.Dispatcher.Invoke(() =>
                            { if (update == null)
                              {
                                  errorTB.Text       = "A ligação ao servidor foi perdida.\nAssim que este esteja operacional reinicie esta aplicação.";
                                  waiting.Visibility = Visibility.Visible;
                              }
                              else
                              {
                                  waiting.Visibility = Visibility.Hidden;
                              } });
 }
Пример #16
0
 public IHttpActionResult AddCompanyUpdate(ServerUpdate companyUpdate)
 {
     try
     {
         var dataRetireved = _companyUpdateService.Save(companyUpdate);
         return(Ok(dataRetireved));
     }
     catch (Exception e)
     {
         ModelState.AddModelError("Error", e.Message);
         return(BadRequest(ModelState));
     }
 }
Пример #17
0
    protected void Undock(ServerUpdate serverUpdate)
    {
        Hangar hangar = _data._hangars[_fleet.LastHangar];

        serverUpdate.Add(hangar);
        foreach (int sID in _fleet.ShipIDs)
        {
            Ship ship = _data._ships[sID];
            ship.Hangar = -1;
            ship.AddLog("undocked from station");
            serverUpdate.Add(ship);
            hangar.Ships.Remove(sID);
        }
    }
Пример #18
0
    protected void Dock(ServerUpdate serverUpdate)
    {
        Hangar hangar = _data._hangars[_fleet.NextHangar];

        serverUpdate.Add(hangar);

        foreach (int sID in _fleet.ShipIDs)
        {
            Ship ship = _data._ships[sID];
            ship.AddLog("Docked to station");
            ship.Hangar = _fleet.NextHangar;
            serverUpdate.Add(ship);
            hangar.Ships.Add(sID);
        }
    }
Пример #19
0
        private byte[] CreateRelease(ServerUpdate companyUpdate, List <Release> recenteRelease)
        {
            var pathDownload = Path.Combine(_directoryPath + $@"\Isolucion_{User.Name}_{recenteRelease.Last().Version}");

            Directory.CreateDirectory(pathDownload);
            foreach (var release in recenteRelease)
            {
                Log.Instance.Info($"Copiando release {release.Version} para descargar");
                System.IO.File.WriteAllBytes($@"{_directoryPath}\{release.Version}.zip", release.ReleaseContent);
                var path = Path.Combine(_directoryPath + $@"\{release.Version}.zip");
                if (!Directory.Exists(path))
                {
                    System.IO.File.Copy(path, $@"{pathDownload}\{release.Version}.zip", true);
                }

                _companyUpdateService.Save(new ServerUpdate
                {
                    ReleaseId = release.Id,
                    ServerId  = companyUpdate.ServerId,
                    Update    = companyUpdate.Update
                });
            }

            _companyUpdateService.CreateXml(new ServerUpdate
            {
                ReleaseId = recenteRelease.LastOrDefault().Id,
                ServerId  = companyUpdate.ServerId,
                Update    = companyUpdate.Update
            }, $@"{pathDownload}\CompanyUpdate.xml");

            if (!Directory.Exists($"{pathDownload}.zip"))
            {
                Compress.CompressFolder($"{pathDownload}.zip", pathDownload);
                Log.Instance.Info($"Comprimiendo archivo {pathDownload}.zip para descargar");
            }

            var fs   = System.IO.File.OpenRead($"{pathDownload}.zip");
            var data = new byte[fs.Length];
            var br   = fs.Read(data, 0, data.Length);

            if (br != fs.Length)
            {
                throw new IOException($"{pathDownload}.zip");
            }
            return(data);
        }
Пример #20
0
    public override int Update(ServerUpdate serverUpdate)
    {
        int doneLoop = _fleet.FleetParams.GetInt("doneLoop", 0);
        int loopToDo = 2;

        if (doneLoop >= loopToDo - 1)
        {
            MoveFlow("FlowOutEnd");
        }
        else
        {
            _fleet.FleetParams.Set("doneLoop", doneLoop + 1);
            MoveFlow("FlowOutRepeat");
        }

        return(_fleet.NextUpdateFrame);
    }
Пример #21
0
    public override int Update(ServerUpdate serverUpdate)
    {
        NodeInfos inputNode = null;
        string    paramName = "";

        foreach (LinkInfo l in _nodes.links)
        {
            if (l.ToID == _myID && l.ToParam == TestValue)
            {
                inputNode = _nodes.nodes[l.FromID];
                paramName = l.FromParam;
            }
        }

        if (null == inputNode)
        {
            throw new System.Exception("No input node for the IfNode");
        }

        ExecutableNode node      = GetNode(inputNode.id);
        IBooleanParam  boolParam = node as IBooleanParam;

        bool result = boolParam.GetBool(paramName);

        if (result)
        {
            foreach (int i in _fleet.ShipIDs)
            {
                Ship ship = _data._ships[i];
                ship.AddLog("Condition checked");
            }
            MoveFlow(OutFlowTrue);
        }
        else
        {
            foreach (int i in _fleet.ShipIDs)
            {
                Ship ship = _data._ships[i];
                ship.AddLog("Condition failed");
            }
            MoveFlow(OutFlowFalse);
        }

        return(_fleet.LastUpdateFrame);
    }
Пример #22
0
    /**
     * Method: getTurn
     * Purpose: Asks the server whose turn it is
     * Parameters: N/A
     * Return Val: N/A
     * */
    public void getTurn()
    {
        client.youWon   = false;                                                                                   //Resets clients win status for new game
        client.gameOver = false;                                                                                   //Resets clients game over status for new game
        Socket sock = SocketFactory.createSocket("localhost", 9999);                                               //Initializes socket
        string req  = "GET /api/game?id=" + client.getGameID() + " HTTP/1.1\r\nHost: " + "localhost:9999\r\n\r\n"; //Asks for current game info

        byte[] sockRequest = Encoding.ASCII.GetBytes(req);
        sock.Send(sockRequest);

        string resp  = "";
        int    bytes = 0;

        byte[] dataReceived = new byte[1024];
        do
        {
            bytes = sock.Receive(dataReceived);                                 //Waits for response from server
            resp  = resp + Encoding.ASCII.GetString(dataReceived, 0, bytes);
        }while (sock.Available > 0);
        print(resp);
        int index = resp.IndexOf("\r\n\r\n");       //Finds location of the body of the header sent back from server

        index += 4;
        resp   = resp.Substring(index);
        ServerUpdate updList = JsonConvert.DeserializeObject <ServerUpdate>(resp);       //Object that contains game data

        if (updList.turn == client.getID())                                              //If it is the local clients turn, then turn the grid on, and set the clients player num to 1
        {
            toggleGrid(true);
            client.setPlayerNum(1);
            print("My turn");
        }
        else                                                                            //If it is not the local clients turn, then turn the grid off, and set the clients number to 2
        {
            toggleGrid(false);
            client.setPlayerNum(2);
            client.setIsTurn(false);
            print("There turn");
        }
        sock.Close();
    }
Пример #23
0
    // -------------------------------------------------------------
    //                              SERVER UPDATES
    // -------------------------------------------------------------
    private void OnServerUpdate(ServerUpdate update)
    {
        foreach (Ship s in update.ships)
        {
            ShipUpdate(s);
        }
        foreach (Hangar h in update.hangars)
        {
            HangarUpdate(h);
        }
        foreach (Corporation c in update.corps)
        {
            CorporationUpdate(c);
        }
        foreach (ResourceStack r in update.stacks)
        {
            ResourceStackUpdate(r);
        }

        SendEvents();
    }
Пример #24
0
        private void ComputeSocketCommunication_Client(Socket socket, SocketRequestCommunication comm)
        {
            int terminalId = SocketConnection.FindTerminal(connections, socket);

            if (terminalId != -1)
            {
                var dbManager = DatabaseManager.getInstance();

                if (comm.ticketCompletedId != -1)
                {
                    dbManager.SetTicketAsComplete(comm.ticketCompletedId, terminalId);
                }

                ServerUpdate su = new ServerUpdate();
                ticket       t  = dbManager.GetNextTicket();
                if (t != null)
                {
                    if (dbManager.SetTicketForClient(t.id, terminalId) == -1)
                    {
                    }

                    su.nextTicket = new Models.TerminalTicket(t);
                    updateCllback.TicketsUpdated(su);

                    MediaPlayer.playNextTicket();
                }
                else
                {
                    su.nextTicket = null;
                }

                var serialized = SerializationManager <ServerUpdate> .Serialize(su);

                new Thread(() => SendData(socket, serialized)).Start();
            }
            else
            {
                throw new Exception();
            }
        }
Пример #25
0
    public override int Update(ServerUpdate serverUpdate)
    {
        SimulatedWideDataManager.SerializeContainer data = SimulatedWideDataManager.Container;


        foreach (int shipID in _fleet.ShipIDs)
        {
            Ship s = data._ships[shipID];
            serverUpdate.Add(s);
            s.Logs += "\n" + "End of flight plan";
        }

        data._fleets.Remove(_fleet.ID);
        foreach (int shipID in _fleet.ShipIDs)
        {
            Ship s = data._ships[shipID];
            serverUpdate.Add(s);
            s.Fleet = 0;
        }

        return(_fleet.NextUpdateFrame);
    }
    public void UpdateOneFrame()
    {
        int frame = _manager.Frame;

        List <Fleet> copy = new List <Fleet>(_container._fleets.Values);


        foreach (Fleet f in copy)
        {
            _currentUpdate = new ServerUpdate();

            if (!_nextChange.ContainsKey(f.ID) || _nextChange[f.ID] <= _container._currentFrame)
            {
                if (!_nextChange.ContainsKey(f.ID))
                {
                    _nextChange.Add(f.ID, 0);
                }
                _nextChange[f.ID] = UpdateFlee(f);
            }
            _manager.SendServerUpdate(_currentUpdate);
            _currentUpdate = null;
        }
    }
Пример #27
0
    public override int Update(ServerUpdate serverUpdate)
    {
        SimulatedWideDataManager.SerializeContainer data = SimulatedWideDataManager.Container;

        foreach (int shipID in _fleet.ShipIDs)
        {
            Ship s = data._ships[shipID];
            serverUpdate.Add(s);
            s.Logs += "\n" + "Starting flight plan";
        }

        //set to next node
        foreach (LinkInfo l in _nodes.links)
        {
            if (l.FromID == _myID && l.FromParam == "StartOutput")
            {
                _fleet.CurrentNode = l.ToID;
                break;
            }
        }

        return(_fleet.NextUpdateFrame);
    }
Пример #28
0
        /// <summary>
        /// Starts listesting for reliable server updates, any received commands are pushed into serverCommands queue.
        /// </summary>
        /// <param name="listenOn">local IP+port on which should the client listen for the reliable updates.</param>
        /// <returns>when server ends the connection or <paramref name="active"/>'' is set.</returns>
        async Task ListenForReliableServerUpdatesAsync(IPEndPoint listenOn)
        {
            using (var listener = new Socket(serverUpdateAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
            {
                listener.Bind(listenOn);
                listener.Listen(5);

                Console.WriteLine($"Started listening for reliable server updates on {listenOn}");
                relUpdatesFromServer = await Task.Factory.FromAsync(listener.BeginAccept, listener.EndAccept, null);

                Console.WriteLine($"Established connection for reliable server updates");
            }
            while (active)
            {
                var bytes = await Communication.TCPReceiveMessageAsync(relUpdatesFromServer);

                var newLastProcessedCUID = Serialization.DecodeInt(bytes, 0);
                var sUpdate = ServerUpdate.Decode(bytes, 4);

                lock (this)
                {
                    //Only add newer updates.
                    if (newLastProcessedCUID >= LastProcessedClientUpdateID)
                    {
                        if (sUpdate is CmdServerUpdate)                        //Contains command
                        {
                            AddServerCommand((sUpdate as CmdServerUpdate).Cmd);
                        }
                        UpdLastProcCUID(newLastProcessedCUID);
                    }
                }
            }

            relUpdatesFromServer.Shutdown(SocketShutdown.Both);
            relUpdatesFromServer.Close();
        }
Пример #29
0
    public override int Update(ServerUpdate serverUpdate)
    {
        MoveFlow(OutFlow);

        return(_fleet.LastUpdateFrame);
    }
Пример #30
0
 public void SendServerUpdate(ServerUpdate s)
 {
     ServerUpdate(s);
 }