public void ResolveRangedCombat(NetworkingPlayer player, NetworkingStream data)
    {
        SmartObject byt = EasySerialization.EasyDeserialize<SmartObject>(ref data);
        int origin = (int) byt.GetObject("obj_0");
        int target = (int) byt.GetObject("obj_1");

        if(scene_combat_model.FindCombatInstance(origin, target) == null)
            return;

        Combat_Model model = scene_combat_model.FindCombatInstance(origin, target);

        if(player.NetworkId != (ulong) 0 && Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
            int random_dice = Random.Range(1, 6);
            if(random_dice >= 5) {
                model.target.entity_model.stats.wounds -= 2;
            } else if(random_dice >= 3) {
                model.target.entity_model.stats.wounds -= 1;
            } else if(random_dice >= 1) {

            }
            model.origin.entity_model.stats.attacks -= 1;
            Network_Command_Manager.instance.CallCustomRPC(ResolveRangedCombat, NetworkReceivers.Others, origin, target);
            Network_Command_Manager.instance.ToNetController<Host_Controller>().ProcessUpdateEntities(new Entity_Model[2] { model.origin.entity_model, model.target.entity_model });
            model.Destroy();
        } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
            model.Destroy();
        }
    }
 //    public void ReadCombatRegister(NetworkingPlayer arg1, NetworkingStream arg2){
 //        SmartObject request = Networking_Utilities.EasyDeserialize<SmartObject> (ref arg2);
 //        switch (request.GetString("type")){
 //        case "Ranged":
 //            CallOnMainThread(delegate {
 //                CallOnMainThread(delegate(object[] obj2) {
 //                    Entity_Controller.instance.AttemptRangedAttack((Entity)obj2[0], (Entity)obj2[1]);
 //                }, new object[2]{Entity_Model.FindEntitybyID(request.GetInt("origin")), Entity_Model.FindEntitybyID(request.GetInt("target"))});
 //            });
 //            break;
 //        }
 //    }
 public void ReadRequest(NetworkingPlayer arg1, NetworkingStream arg2)
 {
     Debug_Console.i.add("New event remote called id " + EventHelper.GetEventId("SERVER_REQUEST") + ", name " + "SERVER_REQUEST");
     SmartObject request = EasySerialization.EasyDeserialize<SmartObject>(ref arg2);
     switch(request.GetString("type")) {
         case "ROTATE_ENTITY":
             CallMainThread(delegate (object[] obj) {
                 if(Entity_Actions.Attempt_Rotate_Entity(((Entity_Model) obj[0]).GetParent, (Vector3) obj[1])) {
                     Debug.Log("Rotation was done successfully");
                     ProcessUpdateEntities(new Entity_Model[1] { ((Entity_Model) obj[0]).GetParent.entity_model });
                 }
             }, new object[2] { request.GetEntity("Entity"), request.GetVec3("Target") });
             break;
         case "MOVE_ENTITY":
             CallMainThread(delegate (object[] obj) {
                 Entity_Actions.Attempt_Move_Entity(((Entity_Model) obj[0]).GetParent, (Vector3) obj[1], delegate (Entity_Model entity_model) {
                     Host_Controller.instance.ToNetController<Host_Controller>().ProcessUpdateEntities(new Entity_Model[1] { entity_model });
                 });
             }, new object[2] { request.GetEntity("Entity"), request.GetVec3("Target") });
             break;
         case "PLAYER_READY":
             Turn_Controller.instance.server_players.GetPlayerByID((int) arg1.NetworkId).ready = true;
             break;
     }
 }
 public void SendChat(NetworkingPlayer player, NetworkingStream stream)
 {
     SmartObject obj = EasySerialization.EasyDeserialize<SmartObject>(ref stream);
     string input = (string) obj.GetObject("obj_0");
     ulong sender_id = (ulong) obj.GetObject("obj_1");
     string sender_name = (Turn_Controller.instance.server_players.GetPlayerByID(sender_id) != null) ? Turn_Controller.instance.server_players.GetPlayerByID(sender_id).name : "Server";
     Debug_Console.i.add(sender_name + " :" + input);
 }
 public void AttemptRangedAttack(NetworkingPlayer player, NetworkingStream data)
 {
     SmartObject obj = EasySerialization.EasyDeserialize<SmartObject>(ref data);
     int origin = (int) obj.GetObject("obj_0");
     int target = (int) obj.GetObject("obj_1");
     if(player.NetworkId != (ulong) 0 && Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
         //			RaycastHit hit;
         //			if(Physics.Linecast(Entity_Model.FindEntitybyID(origin).transform.position, Entity_Model.FindEntitybyID(target).transform.position, out hit, no_characters)){
         combat_controller.scene_combat_model.AddRangeInstance(Entity_Model.FindEntitybyID(origin), Entity_Model.FindEntitybyID(target));
         Network_Command_Manager.instance.CallCustomRPC(AttemptRangedAttack, NetworkReceivers.Others, origin, target);
         Debug_Console.i.add("This server was asked to create combat");
         //			}
     } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
         combat_controller.scene_combat_model.AddRangeInstance(Entity_Model.FindEntitybyID(origin), Entity_Model.FindEntitybyID(target));
         Debug_Console.i.add("server sent combat");
     }
 }
 public void ResetBetweenPhase(NetworkingPlayer player, NetworkingStream stream)
 {
     if(Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
         foreach(Combat_Model combat in Combat_Controller.instance.scene_combat_model.combat_instances.ToArray()) {
             combat.Destroy();
         }
         Combat_Controller.instance.scene_combat_model.combat_groups = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.first_initative = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.second_initative = new List<Melee_Combat_Group_Model>();
         Network_Command_Manager.instance.CallCustomRPC(ResetBetweenPhase, NetworkReceivers.Others, server_players.active_team);
     } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
         foreach(Combat_Model combat in Combat_Controller.instance.scene_combat_model.combat_instances.ToArray()) {
             combat.Destroy();
         }
         Combat_Controller.instance.scene_combat_model.combat_groups = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.first_initative = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.second_initative = new List<Melee_Combat_Group_Model>();
     }
 }
 public void SetupMeleeInstance(NetworkingPlayer player, NetworkingStream data)
 {
     SmartObject obj = EasySerialization.EasyDeserialize<SmartObject>(ref data);
     int origin = (int) obj.GetObject("obj_0");
     int target = (int) obj.GetObject("obj_1");
     if(Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
         Network_Command_Manager.instance.CallCustomRPC(SetupMeleeInstance, NetworkReceivers.Others, origin, target);
     } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
         combat_controller.scene_combat_model.AddMeleeInstance(Entity_Model.FindEntitybyID(origin), Entity_Model.FindEntitybyID(target));
         Debug_Console.i.add("server sent combat");
     }
 }
Exemple #7
0
        /// <summary>
        /// Decode the message that was receieved over the network, this is after it has been fully
        /// parsed into a complete byte array
        /// </summary>
        /// <param name="bytes">The bytes that are to be decoded</param>
        /// <param name="useMask">Determines if a mask was used and if it should find the mask</param>
        /// <returns>The frame that was found during decoding</returns>
        public static FrameStream DecodeMessage(byte[] bytes, bool useMask, int groupId, NetworkingPlayer sender, byte receivers = 255)
        {
            int indexFirstMask = 0;

            byte[] decoded = DecodeHead(bytes, useMask, out indexFirstMask);
            return(ReadFrameStream(bytes[0], decoded, indexFirstMask, groupId, sender, receivers));
        }
 private void ExecuteRouterAction(byte routerId, NetworkObject networkObject, Binary frame, NetworkingPlayer player)
 {
     // 执行RPC函数
     if (routerId == RouterIds.RPC_ROUTER_ID)
     {
         networkObject.InvokeRpc(player, frame.TimeStep, frame.StreamData, frame.Receivers);
     }
     else if (routerId == RouterIds.BINARY_DATA_ROUTER_ID)
     {
         networkObject.ReadBinaryData(frame);
     }
     else if (routerId == RouterIds.CREATED_OBJECT_ROUTER_ID)
     {
         networkObject.CreateConfirmed(player);
     }
 }
 private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
 {
     Debug.Log("Reading");
     Deserialize(stream);
 }
Exemple #10
0
 // 接收二进制数据
 public void OnBinaryMessageReceived(NetworkingPlayer player, Binary frame, NetWorker sender)
 {
     byte routerId = frame.RouterId;
 }
Exemple #11
0
        /// <summary>
        /// Called when the network as interpreted that a cache message has been sent from the server
        /// </summary>
        /// <param name="player">The server</param>
        /// <param name="frame">The data that was received</param>
        /// <summary>
        ///当网络被解释为缓存消息已经从服务器发送时调用
        /// </ summary>
        /// <param name =“player”>服务器</ param>
        /// <param name =“frame”>收到的数据</ param>
        private void BinaryMessageReceived(NetworkingPlayer player, Binary frame, NetWorker sender)
        {
            if (frame.GroupId != MessageGroupIds.CACHE)
            {
                return;
            }

            if (sender is IServer)
            {
                byte   type           = ObjectMapper.Instance.Map <byte>(frame.StreamData);
                int    responseHookId = ObjectMapper.Instance.Map <int>(frame.StreamData);
                string key            = ObjectMapper.Instance.Map <string>(frame.StreamData);

                object obj = Get(key);

                // TODO:  Let the client know it is null
                if (obj == null)
                {
                    return;
                }

                BMSByte data = ObjectMapper.BMSByte(type, responseHookId, obj);

                Binary sendFrame = new Binary(sender.Time.Timestep, sender is TCPClient, data, Receivers.Target, MessageGroupIds.CACHE, sender is BaseTCP);

                if (sender is BaseTCP)
                {
                    ((TCPServer)sender).Send(player.TcpClientHandle, sendFrame);
                }
                else
                {
                    ((UDPServer)sender).Send(player, sendFrame, true);
                }
            }
            else
            {
                byte type           = ObjectMapper.Instance.Map <byte>(frame.StreamData);
                int  responseHookId = ObjectMapper.Instance.Map <int>(frame.StreamData);

                object obj = null;

                if (typeMap[type] == typeof(string))
                {
                    obj = ObjectMapper.Instance.Map <string>(frame.StreamData);
                }

                /*else if (typeMap[type] == typeof(Vector2))
                 *      obj = ObjectMapper.Map<Vector2>(stream);
                 * else if (typeMap[type] == typeof(Vector3))
                 *      obj = ObjectMapper.Map<Vector3>(stream);
                 * else if (typeMap[type] == typeof(Vector4))
                 *      obj = ObjectMapper.Map<Vector4>(stream);
                 * else if (typeMap[type] == typeof(Color))
                 *      obj = ObjectMapper.Map<Color>(stream);
                 * else if (typeMap[type] == typeof(Quaternion))
                 *      obj = ObjectMapper.Map<Quaternion>(stream);*/
                else
                {
                    obj = ObjectMapper.Instance.Map(typeMap[type], frame.StreamData);
                }

                if (responseHooks.ContainsKey(responseHookId))
                {
                    responseHooks[responseHookId](obj);
                    responseHooks.Remove(responseHookId);
                }
            }
        }
Exemple #12
0
 public void IssueChallenge(NetWorker networker, NetworkingPlayer player, System.Action <NetworkingPlayer, BMSByte> issueChallengeAction, System.Action <NetworkingPlayer> skipAuthAction)
 {
     issueChallengeAction(player, ObjectMapper.BMSByte(status));
 }
Exemple #13
0
 private void OnPlayerJoined(NetworkingPlayer networkingPlayer)
 {
     SendBuffer(networkingPlayer);
     scene.OnPlayerAccepted(networkingPlayer);
 }
	private void PrimarySocket_rawDataRead(NetworkingPlayer sender, BMSByte data)
	{
		// Print out the id and the convert the bytes to a string to print
		Debug.Log("Received message from " + sender.NetworkId + ", payload to string says: " + System.Text.Encoding.UTF8.GetString(data.byteArr, data.StartIndex(), data.Size));
	}
 public virtual void ServerSendAll(FrameStream frame, bool reliable = false, NetworkingPlayer skipPlayer = null)
 {
     ((NetRoomServer)Room).Send(frame, reliable);
 }
Exemple #16
0
 protected override bool AllowOwnershipChange(NetworkingPlayer newOwner)
 {
     // The newOwner is the NetworkingPlayer that is requesting the ownership change, you can get the current owner with just "Owner"
     return(true);
 }
 public Ping(byte[] frame, int payloadStart, int groupId, NetworkingPlayer sender, byte receivers) : base(frame, payloadStart, groupId, sender, receivers)
 {
 }
        private void Get(NetworkingPlayer player, JSONNode data)
        {
            // Pull the game id and the filters from request
            string gameId   = data["id"];
            string gameType = data["type"];
            string gameMode = data["mode"];

            if (_playerRequests.ContainsKey(player.Ip))
            {
                _playerRequests[player.Ip]++;
            }
            else
            {
                _playerRequests.Add(player.Ip, 1);
            }

            int delta = _playerRequests[player.Ip];

            // Get only the list that has the game ids
            List <Host> filter = (from host in hosts where host.Id == gameId select host).ToList();

            // If "any" is supplied use all the types for this game id otherwise select only matching types
            if (gameType != "any")
            {
                filter = (from host in filter where host.Type == gameType select host).ToList();
            }

            // If "all" is supplied use all the modes for this game id otherwise select only matching modes
            if (gameMode != "all")
            {
                filter = (from host in filter where host.Mode == gameMode select host).ToList();
            }

            // Prepare the data to be sent back to the client
            JSONNode  sendData    = JSONNode.Parse("{}");
            JSONArray filterHosts = new JSONArray();

            foreach (Host host in filter)
            {
                JSONClass hostData = new JSONClass();
                hostData.Add("name", host.Name);
                hostData.Add("address", host.Address);
                hostData.Add("port", new JSONData(host.Port));
                hostData.Add("comment", host.Comment);
                hostData.Add("type", host.Type);
                hostData.Add("mode", host.Mode);
                hostData.Add("players", new JSONData(host.PlayerCount));
                hostData.Add("maxPlayers", new JSONData(host.MaxPlayers));
                hostData.Add("protocol", host.Protocol);
                filterHosts.Add(hostData);
            }

            if (filterHosts.Count > 0)
            {
                _playerRequests.Remove(player.Ip);
            }

            sendData.Add("hosts", filterHosts);

            Log("Sending: " + sendData.ToString());

            // Send the list of hosts (if any) back to the requesting client
            server.Send(player, Text.CreateFromString(server.Time.Timestep, sendData.ToString(), false, Receivers.Target, MessageGroupIds.MASTER_SERVER_GET, true));
        }
Exemple #19
0
 private static void TextMessageRead(NetworkingPlayer player, Text frame, NetWorker sender)
 {
     responsePlayer = player;
     response       = frame.ToString();
 }
Exemple #20
0
 private static void BinaryMessageRead(NetworkingPlayer player, Binary frame, NetWorker sender)
 {
     responsePlayer = player;
     response       = ObjectMapper.Instance.Map <string>(frame.StreamData);
 }
Exemple #21
0
        public static FrameStream ReadFrameStream(byte firstByte, byte[] decoded, int indexFirstMask, int groupId, NetworkingPlayer sender, byte receivers = 255)
        {
            // TCP sends as a stream, so we didn't get the group id from the packet compilation
            // In this case we need to read it as the first set of bytes after the mask
            if (groupId == MessageGroupIds.TCP_FIND_GROUP_ID)
            {
                groupId        = BitConverter.ToInt32(decoded, 0);
                indexFirstMask = 4;
            }
            else
            {
                indexFirstMask = 0;
            }

            // Find out what kind of frame this is and construct the appropriate frame for reading
            switch (firstByte)
            {
            case Binary.CONTROL_BYTE:
                return(new Binary(decoded, indexFirstMask, groupId, sender, receivers));

            case ConnectionClose.CONTROL_BYTE:
                return(new ConnectionClose(decoded, indexFirstMask, groupId, sender, receivers));

            case Continuation.CONTROL_BYTE:
                return(new Continuation(decoded, indexFirstMask, groupId, sender, receivers));

            case Error.CONTROL_BYTE:
                return(new Error(decoded, indexFirstMask, groupId, sender, receivers));

            case Ping.CONTROL_BYTE:
                return(new Ping(decoded, indexFirstMask, groupId, sender, receivers));

            case Pong.CONTROL_BYTE:
                return(new Pong(decoded, indexFirstMask, groupId, sender, receivers));

            case Text.CONTROL_BYTE:
                return(new Text(decoded, indexFirstMask, groupId, sender, receivers));

            default:
                throw new BaseNetworkException("Message received but header doesn't define correct frame type.");
            }
        }
 public virtual void ServerSend(NetworkingPlayer player, FrameStream frame, bool reliable = false)
 {
     ((NetRoomServer)Room).Send(player, frame, reliable);
 }