示例#1
0
        /// <summary>
        /// Method called when the server sends a message that the flight stage started
        /// </summary>
        /// <param name="parts"></param>
        private void FlightBegunResolve(string[] parts)
        {
            if (!IsReady)
            {
                _pingTimer.Stop();
                _pingTimer.Dispose();
                throw new OutOfSyncException();
            }
            IsReady = false;
            foreach (PlayerInfo info in PlayerInfos.Values)
            {
                info.IsReady = false;
            }
            _serverStage = ServerStage.Flight;
            //Format: FlightBegun,PlayerNumber,Color,Firepower,Enginepower,CrewCount,StorageSize,Batteries
            int playerNumber = int.Parse(parts[1]);

            for (int i = 0; i < playerNumber; ++i)
            {
                PlayerColor currentPlayer = Enum.Parse <PlayerColor>(parts[2 + i * 6]);
                PlayerInfos[currentPlayer].Attributes = new PlayerAttributes
                {
                    Firepower   = int.Parse(parts[3 + i * 6]),
                    Enginepower = int.Parse(parts[4 + i * 6]),
                    CrewCount   = int.Parse(parts[5 + i * 6]),
                    StorageSize = int.Parse(parts[6 + i * 6]),
                    Batteries   = int.Parse(parts[7 + i * 6]),
                };
            }
            FlightBegun?.Invoke(this, EventArgs.Empty);
        }
示例#2
0
        public void InvokeRpc(NetworkConnection conn, string methodName, RpcArgs args, int priority)
        {
            NetworkMessage.RpcInvokeMessage rpcDef = new NetworkMessage.RpcInvokeMessage(instanceId, priority, methodName, args);

            if (ServerStage.active)
            {
                ServerStage.SendNetworkMessage(rpcDef, conn);
            }
        }
示例#3
0
        public void SendVariableUpdate(SyncVar var)
        {
            if (!ServerStage.active)
            {
                return;
            }

            NetworkMessage.SyncVarUpdateMessage msg = new NetworkMessage.SyncVarUpdateMessage(instanceId, var.VariableName, var.currentItem);
            ServerStage.SendHighPriorityNetworkMessage(msg);
        }
示例#4
0
    private void SpawnPlayer(NetworkMessage msg)
    {
        //Debug.Log("Received spawn message.");

        NetworkEntity cubie1 = Instantiate(cubie, Vector3.right * 3, Quaternion.identity);

        NetworkSpawnArgs.TestArgs args = new NetworkSpawnArgs.TestArgs();
        args.value = "cubie1";
        ServerStage.ServerSpawn(cubie1, msg.senderConnection, args);
    }
示例#5
0
 public GTTcpClient()
 {
     PlayerInfos  = new Dictionary <PlayerColor, PlayerInfo>();
     _playerOrder = new List <PlayerColor>();
     IsReady      = false;
     _serverStage = ServerStage.Lobby;
     _client      = new TcpClient();
     _pingTimer   = new Timer(PingInterval);
     Crashed      = false;
 }
示例#6
0
    private void OnDestroy()
    {
        if (ClientStage.active)
        {
            ClientStage.DisconnectClient();
        }

        if (ServerStage.active)
        {
            ServerStage.Disconnect();
        }
    }
示例#7
0
    private void Update()
    {
        if (ClientStage.active)
        {
            ClientStage.Tick();
        }

        if (ServerStage.active)
        {
            ServerStage.Tick();
        }
    }
示例#8
0
 /// <summary>
 /// Method called when the server sends a message that flight stage ended, either because there are no more cards left, or all players crashed
 /// </summary>
 private void FlightEndedResolve()
 {
     if (_serverStage != ServerStage.Flight)
     {
         _pingTimer.Stop();
         _pingTimer.Dispose();
         throw new OutOfSyncException();
     }
     Card.Dispose();
     _serverStage = ServerStage.PastFlight;
     FlightEnded?.Invoke(this, EventArgs.Empty);
 }
示例#9
0
 public WebServerTaskCreator()
 {
     Task = new WebProgressTask()
     {
         CurrentStage = ServerStage.FIRST_STAGE,
         Connection   = new HttpConnection
         {
             Ip = "127.0.0.1",
         },
         NetworkStream = new MemoryStream()
     };
     TerminationStage = ServerStage.FINAL_STAGE;
 }
示例#10
0
    public void StartServer()
    {
        ServerStage.StartServer(47777);
        ServerStage.AddEntityDefinitions(spawnableObjects);

        ServerStage.RegisterMessageEvent(NetworkMessage.SpawnPlayer, SpawnPlayer);

        ServerStage.Ready();

        ServerConsoleCommands.AddConsoleCommand("Try", LoopTry);

        //NetworkEntity cubie1 = Instantiate(cubie, Vector3.right * 3, Quaternion.identity);
        //ServerStage.ServerSpawn(cubie1);
    }
示例#11
0
        public void InvokeRpc(string methodName, RpcArgs args, int priority)
        {
            NetworkMessage.RpcInvokeMessage rpcDef = new NetworkMessage.RpcInvokeMessage(instanceId, priority, methodName, args);

            if (ClientStage.active)
            {
                ClientStage.SendNetworkMessage(rpcDef);
            }

            if (ServerStage.active)
            {
                ServerStage.SendNetworkMessage(rpcDef);
            }
        }
示例#12
0
        /// <summary>
        /// Method to toggle the player's ready state
        /// </summary>
        /// <param name="currentStage"></param>
        public void ToggleReady(ServerStage currentStage)
        {
            if (_serverStage != currentStage)
            {
                _pingTimer.Stop();
                _pingTimer.Dispose();
                throw new InvalidOperationException();
            }

            WriteMessageToServer("ToggleReady");

            IsReady = !IsReady;
            PlayerInfos[Player].IsReady = IsReady;
            ThisPlayerReadied?.Invoke(this, EventArgs.Empty);
        }
示例#13
0
 /// <summary>
 /// Method called when the server sends a message to signal that the building stage started
 /// </summary>
 /// <param name="parts"></param>
 private void BuildingBegunResolve()
 {
     if (!IsReady)
     {
         _pingTimer.Stop();
         _pingTimer.Dispose();
         throw new OutOfSyncException();
     }
     IsReady = false;
     foreach (PlayerInfo info in PlayerInfos.Values)
     {
         info.IsReady = false;
     }
     _serverStage = ServerStage.Build;
     BuildingBegun?.Invoke(this, EventArgs.Empty);
 }
示例#14
0
 internal protected virtual async Task ExecuteTaskChain(WebProgressTask task, ServerStage terminationState = ServerStage.FINAL_STAGE)
 {
     if (task == null)
     {
         return;
     }
     while (true)
     {
         using var watch = task.Monitor.Watch(this, $"Web Service Group: {task.CurrentStage}");
         await WebServiceGroups[task.CurrentStage].Execute(task).ConfigureAwait(false);
         if (task.CurrentStage == terminationState)
         {
             break;
         }
         task.CurrentStage = task.NextStage;
         task.NextStage    = task.NextStage == ServerStage.FINAL_STAGE
             ? ServerStage.FINAL_STAGE
             : (ServerStage)((int)task.NextStage + 1);
     }
 }
示例#15
0
        /// <summary>
        /// Method called when the server sends a message to signal that the building stage ended
        /// </summary>
        /// <param name="parts"></param>
        private void BuildingEndedResolve(string[] parts)
        {
            if (!IsReady)
            {
                _pingTimer.Stop();
                _pingTimer.Dispose();
                throw new OutOfSyncException();
            }
            IsReady = false;
            foreach (PlayerInfo info in PlayerInfos.Values)
            {
                info.IsReady = false;
            }
            for (int i = 1; i < parts.Length; ++i)
            {
                _playerOrder.Add(Enum.Parse <PlayerColor>(parts[i]));
            }

            _orderManager = new PlayerOrderManager(_playerOrder, GameStage);

            _orderManager.PlacesChanged += (sender, e) =>
            {
                PlacesChanged?.Invoke(this, e);
            };

            _orderManager.PlayerCrashed += (sender, e) =>
            {
                if (e == Player)
                {
                    Crashed = true;
                }
                PlayerInfos[e].IsFlying = false;
                PlayerCrashed?.Invoke(this, e);
            };

            _serverStage = ServerStage.PastBuild;
            BuildingEnded?.Invoke(this, EventArgs.Empty);
        }
示例#16
0
    public void InvokePositionUpdate()
    {
        if (ClientStage.active && !myNetworkEntity.IsLocalObject())
        {
            return;
        }

        NetworkMessage.UpdateTransformMessage transformMsg = new NetworkMessage.UpdateTransformMessage(myNetworkEntity.instanceId, transform.position, transform.rotation, childTransform.localPosition, childTransform.rotation, _velocity);

        if (ClientStage.active)
        {
            ClientStage.SendNetworkMessage(transformMsg);
        }

        if (ServerStage.active)
        {
            ServerStage.SendNetworkMessage(transformMsg);
        }

        previousPosition      = transform.position;
        previousRotation      = transform.rotation;
        previousChildPosition = childTransform.localPosition;
        previousChildRotation = childTransform.rotation;
    }
 /// <summary>
 /// This is a service collection that contains multiple <see cref="WebService" />. For
 /// execution this will search for the first containing service that matches the condition
 /// and execute them. Therefore this service collection is not suitable if you want to use
 /// multiple services in the same stage.
 /// </summary>
 /// <param name="stage">The <see cref="ServerStage" /> this collection is pinned to</param>
 public WebServiceCollection(ServerStage stage)
     : base(stage)
 {
 }
示例#18
0
 public WebService(ServerStage stage)
 {
     Stage = stage;
 }
示例#19
0
 public WebService2(ServerStage stage)
     : base(stage)
 {
 }
示例#20
0
 public void ResetServer()
 {
     ServerStage.ResetServer();
 }
 public Task Execute(WebProgressTask task, ServerStage terminationState = ServerStage.FINAL_STAGE)
 {
     _ = task ?? throw new ArgumentNullException(nameof(task));
     return(ExecuteTaskChain(task, terminationState));
 }
示例#22
0
 public WebServiceGroup(ServerStage stage)
 {
     Stage    = stage;
     Services = new PriorityList <WebServicePriority, WebService>();
 }