コード例 #1
0
        public override void OnSetProperties(ISetPropertiesCallInfo info)
        {
            base.OnSetProperties(info);

            var setPropertiesRequest = info.Request;
            var url = this.gamePropertiesUrl;

            if (setPropertiesRequest.HttpForward && !string.IsNullOrEmpty(url))
            {
                var state = WebFlags.ShouldSendState(info.Request.WebFlags) ? this.GetGameState() : null;

                this.PostJsonRequest(
                    url,
                    new WebhooksRequest
                {
                    Type        = info.Request.ActorNumber == 0 ? "Game" : "Actor",
                    TargetActor = info.Request.ActorNumber == 0 ? null : (int?)info.Request.ActorNumber,
                    GameId      = this.PluginHost.GameId,
                    AppId       = this.AppId,
                    AppVersion  = this.AppVersion,
                    Region      = this.Region,
                    UserId      = info.UserId,
                    Nickname    = info.Nickname,
                    ActorNr     = info.ActorNr,
                    Properties  = setPropertiesRequest.Properties,
                    State       = state,
                    AuthCookie  = WebFlags.ShouldSendAuthCookie(info.Request.WebFlags) ? info.AuthCookie : null,
                },
                    this.LogIfFailedCallback,
                    null,
                    callAsync: !WebFlags.ShouldSendSync(info.Request.WebFlags));
            }
        }
コード例 #2
0
        public static bool RemoveExpectedUsers(this Room room, string[] userIds, WebFlags webFlags = null, bool broadcast = true)
        {
            if (userIds == null || userIds.Length == 0)
            {
                return(false);
            }

            if (room.ExpectedUsers == null || room.ExpectedUsers.Length == 0)
            {
                return(false);
            }

            if (userIds.Length > room.ExpectedUsers.Length)
            {
                return(false);
            }

            HashSet <string> hashSet = new HashSet <string>(room.ExpectedUsers);

            for (int i = 0; i < userIds.Length; i++)
            {
                string userId = userIds[i];
                if (string.IsNullOrEmpty(userId))
                {
                    return(false);
                }

                if (!hashSet.Remove(userId))
                {
                    return(false);
                }
            }

            return(room.SetExpectedUsers(hashSet, webFlags: webFlags, broadcast: broadcast));
        }
コード例 #3
0
        public override void OnLeave(ILeaveGameCallInfo info)
        {
            base.OnLeave(info);

            var url = this.gameLeaveUrl;

            if (!string.IsNullOrEmpty(url)) // && info.ActorNr != -1 we don't restrict this anymore as in forwardplugin to see all leaves
            {
                this.PostJsonRequest(
                    url,
                    new WebhooksRequest
                {
                    Type       = LeaveReason.ToString(info.Reason),
                    GameId     = this.PluginHost.GameId,
                    AppId      = this.AppId,
                    AppVersion = this.AppVersion,
                    Region     = this.Region,
                    UserId     = info.UserId,
                    Nickname   = info.Nickname,
                    ActorNr    = info.ActorNr,
                    IsInactive = info.IsInactive,
                    Reason     = info.Reason.ToString(),
                    AuthCookie = WebFlags.ShouldSendAuthCookie(info.Request.WebFlags) ? info.AuthCookie : null,
                },
                    this.LogIfFailedCallback,
                    callAsync: true);
            }
        }
コード例 #4
0
    public static void SendGameData()
    {
        //use this space to add player info to data array


        string[] GameArray = GameData.ToArray();


        //clear data
        GameData = new List <string>();


        // Raise custom room event
        // Replace 15 with any custom event code of your choice [0..299]
        //RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All }; // You would have to set the Receivers to All in order to receive this event on the local client as well
        //SendOptions sendOptions = new SendOptions { Reliability = true };
        //SendOptions sendOptions = new SendOptions { Reliability = true };
        //PhotonNetwork.RaiseEvent(15, "nicolastesting", RaiseEventOptions.Default, sendOptions: Sendreliable);// WebFlags.Default);
        byte evCode = 1; // Custom Event 1: Used as "MoveUnitsToTargetPosition" event

        //object[] content = new object[] { "testing" };
        object[]          content           = new object[] { GameArray }; // Array contains the target position and the IDs of the selected units
        var               flags             = new WebFlags(WebFlags.HttpForwardConst);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All, Flags = flags
        };                                                                                                            // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);
    }
コード例 #5
0
        public override void OnRaiseEvent(IRaiseEventCallInfo info)
        {
            base.OnRaiseEvent(info);

            var raiseEventRequest = info.Request;
            var url = this.gameEventUrl;

            if (raiseEventRequest.HttpForward && !string.IsNullOrEmpty(url))
            {
                var state = WebFlags.ShouldSendState(info.Request.WebFlags) ? this.GetGameState() : null;

                this.PostJsonRequest(
                    url,
                    new WebhooksRequest
                {
                    Type       = "Event",
                    GameId     = this.PluginHost.GameId,
                    AppId      = this.AppId,
                    AppVersion = this.AppVersion,
                    Region     = this.Region,
                    UserId     = info.UserId,
                    Nickname   = info.Nickname,
                    ActorNr    = info.ActorNr,
                    Data       = raiseEventRequest.Data,
                    State      = state,
                    AuthCookie = WebFlags.ShouldSendAuthCookie(info.Request.WebFlags) ? info.AuthCookie : null,
                    EvCode     = raiseEventRequest.EvCode,
                },
                    this.LogIfFailedCallback,
                    null,
                    callAsync: !WebFlags.ShouldSendSync(info.Request.WebFlags));
            }
        }
コード例 #6
0
        /// <summary>
        /// Defines a property on this Player.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="propertyName"></param>
        /// <param name="propertyValue"></param>
        public static void SetProperty <T>(this Player player, string propertyName, T propertyValue, bool webFoward)
        {
            /*if (!PhotonNetwork.connectedAndReady)
             * {
             *  Debug.LogWarning("JoinTeam was called in state: " + PhotonNetwork.connectionStateDetailed + ". Not connectedAndReady.");
             * }*/

            //T currentProp = (T)player.GetProperty(propertyName);
            //if (currentProp != propertyValue)
            //{

            if (webFoward)
            {
                var flags = new WebFlags(0);
                //flags.SendSync = false;
                //flags.SendState = true;
                flags.HttpForward = true;
                player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable()
                {
                    { propertyName, propertyValue }
                }, null, flags);
            }
            else
            {
                player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable()
                {
                    { propertyName, propertyValue }
                }, null, null);
            }

            //Debug.Log("Player SetProperty " + player.ToStringFull() + " / currentProp" + currentProp + " / propertyName" + propertyName + " / propertyValue" + propertyValue);
            //}
        }
コード例 #7
0
    public void SendEvaluationData()
    {
        //use this space to add player info to data array


        List <string> StringList = new List <string>();

        StringList.Add(QuestionString);
        //StringList.Add(remarks);
        //PhotonView[] View_array = PhotonNetwork.PhotonViews;
        //foreach (PhotonView view in View_array)
        //{


        //    if (!view.IsMine)
        //    {
        //        GameObject Player_object = view.gameObject;//

        //        if (Player_object.tag == "Player")
        //        {
        //            StringList.Add("Player " + view.OwnerActorNr.ToString());
        //            StringList.Add(Player_object.GetComponent<EndLobbyWork>().QuestionString);
        //            StringList.Add(Player_object.GetComponent<EndLobbyWork>().remarks);
        //        }
        //    }

        //}


        string[] GameArray = StringList.ToArray();
        byte     evCode    = 1; // Custom Event 1: Used as "MoveUnitsToTargetPosition" event

        //object[] content = new object[] { "testing" };
        object[]          content           = new object[] { GameArray }; // Array contains the target position and the IDs of the selected units
        var               flags             = new WebFlags(WebFlags.HttpForwardConst);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All, Flags = flags
        };                                                                                                            // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);
    }
コード例 #8
0
    //public static void OutputPlayervars(int ID, float tempvar)
    //{
    //    if (ID == 1)
    //    {
    //        CommonList[0] = tempvar.ToString();
    //    }
    //    else
    //    {


    //        CommonList[1] = tempvar.ToString();

    //    }


    //}

    void OutputCommondata()
    {
        var JointStrings = String.Join(",", CommonList);


        byte evCode = 2;                                                     // Custom Event 1: Used as "MoveUnitsToTargetPosition" event

        object[]          content           = new object[] { JointStrings }; // Array contains the target position and the IDs of the selected units
        var               flags             = new WebFlags(WebFlags.HttpForwardConst);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All, Flags = flags
        };                                                                                                            // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);
        Debug.Log(JointStrings);
    }
コード例 #9
0
ファイル: Network.cs プロジェクト: yeoez001/PhotonHands
    public static bool SetCustomPropertySafe(string key, object newValue, WebFlags webFlags = null)
    {
        Room room = PhotonNetwork.CurrentRoom;

        if (room == null || room.IsOffline)
        {
            return(false);
        }

        ExitGames.Client.Photon.Hashtable props = room.CustomProperties;

        if (room.CustomProperties.ContainsKey(key))
        {
            props[key] = newValue;
        }
        else
        {
            props.Add(key, newValue);
        }
        return(room.LoadBalancingClient.OpSetCustomPropertiesOfRoom(props /*, oldProps, webFlags);*/));
    }
コード例 #10
0
        internal static void Postfix(GorillaTagManager __instance, Player taggedPlayer, Player taggingPlayer)
        {
            if (__instance.photonView.IsMine && taggedPlayer == taggingPlayer)
            {
                RaiseEventOptions raiseEventOptions = new RaiseEventOptions();
                WebFlags          flags             = new WebFlags(1);
                raiseEventOptions.Flags = flags;

                if (__instance.isCurrentlyTag)
                {
                    if (__instance.currentIt != taggedPlayer)
                    {
                        __instance.ChangeCurrentIt(taggedPlayer);
                        __instance.lastTag = UnityEngine.Time.time;

                        object[] eventContent = new object[]
                        {
                            taggingPlayer.UserId,
                            taggedPlayer.UserId
                        };

                        PhotonNetwork.RaiseEvent(1, eventContent, raiseEventOptions, SendOptions.SendReliable);
                    }
                }
                else
                {
                    if (!__instance.currentInfected.Contains(taggedPlayer))
                    {
                        __instance.AddInfectedPlayer(taggedPlayer);
                        object[] eventContent2 = new object[]
                        {
                            taggingPlayer.UserId,
                            taggedPlayer.UserId,
                            __instance.currentInfected.Count
                        };
                        PhotonNetwork.RaiseEvent(2, eventContent2, raiseEventOptions, SendOptions.SendReliable);
                    }
                }
            }
        }
コード例 #11
0
    public void SendQuestionnaireData()
    {
        //use this space to add player info to data array
        string        QuestionString = "P" + (this.photonView.OwnerActorNr - 1).ToString() + sex + "," + age + "," + experience + "," + Answer1.ToString() + "_" + Answer2.ToString() + "_" + Answer3.ToString() + "_" + Answer4.ToString() + "_" + Answer5.ToString(); //+ "_" + Answer6.ToString();
        List <string> StringList     = new List <string>();

        StringList.Add(QuestionString);
        string[] GameArray = StringList.ToArray();
        byte     evCode    = 1; // Custom Event 1: Used as "MoveUnitsToTargetPosition" event

        //object[] content = new object[] { "testing" };
        object[]          content           = new object[] { GameArray }; // Array contains the target position and the IDs of the selected units
        var               flags             = new WebFlags(WebFlags.HttpForwardConst);
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All, Flags = flags
        };                                                                                                            // You would have to set the Receivers to All in order to receive this event on the local client as well
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);
    }
コード例 #12
0
        private string SerializeRequest(WebRpcRequest request, string userId, object authResultsSecure)
        {
            if (request.RpcParams != null && typeof(Dictionary <string, object>) == request.RpcParams.GetType())
            {
                var rpcParams = (Dictionary <string, object>)request.RpcParams;

                rpcParams["AppId"]      = this.environment == null ? null : this.environment["AppId"];
                rpcParams["AppVersion"] = this.environment == null ? null : this.environment["AppVersion"];
                rpcParams["Region"]     = this.environment == null ? null : this.environment["Region"];
                rpcParams["UserId"]     = userId;
                if (WebFlags.ShouldSendAuthCookie(request.WebFlags))
                {
                    rpcParams["AuthCookie"] = authResultsSecure;
                }

                return(Newtonsoft.Json.JsonConvert.SerializeObject(rpcParams));
            }
            else
            {
                var rpcParams = new Dictionary <string, object>();

                rpcParams["AppId"]      = this.environment == null ? null : this.environment["AppId"];
                rpcParams["AppVersion"] = this.environment == null ? null : this.environment["AppVersion"];
                rpcParams["Region"]     = this.environment == null ? null : this.environment["Region"];
                rpcParams["UserId"]     = userId;
                if (WebFlags.ShouldSendAuthCookie(request.WebFlags))
                {
                    rpcParams["AuthCookie"] = authResultsSecure;
                }
                if (request.RpcParams != null)
                {
                    rpcParams["RpcParams"] = request.RpcParams;
                }

                return(Newtonsoft.Json.JsonConvert.SerializeObject(rpcParams));
            }
        }
コード例 #13
0
        /// <summary>
        /// Tries to send SetProperties operation.
        /// If actorNr param is 0 then it's for room properties.
        /// If actorNr param is higher than 0 then it's for actor properties.
        /// </summary>
        /// <param name="client">LoadBalancingClient instance to send the operation request.</param>
        /// <param name="actorNr">Target actor number of the properties to set. 0 for room properties.</param>
        /// <param name="properties">Properties to set.</param>
        /// <param name="expectedProperties">Properties used in Check-And-Swap or Compare-And-Set</param>
        /// <param name="webFlags">Flags to define PathGameProperties WebHook behaviour.</param>
        /// <param name="notify">Whether or not this operation should result in PropertiesChanged event sent to joined actors to sync their cached properties.</param>
        /// <param name="sendOptions">Generic options affecting the operation request.</param>
        /// <returns></returns>
        public static bool OpSetProperties(this LoadBalancingClient client, int actorNr, Hashtable properties, Hashtable expectedProperties = null, WebFlags webFlags = null, bool notify = true,
                                           SendOptions sendOptions = default)
        {
            Dictionary <byte, object> opParameters = new Dictionary <byte, object>();

            if (properties != null)
            {
                opParameters.Add(ParameterCode.Properties, properties);
            }
            if (actorNr > 0)
            {
                opParameters.Add(ParameterCode.ActorNr, actorNr);
            }
            if (notify)
            {
                opParameters.Add(ParameterCode.Broadcast, true);
            }
            if (expectedProperties != null)
            {
                opParameters.Add(ParameterCode.ExpectedValues, expectedProperties);
            }
            if (webFlags != null)
            {
                opParameters[ParameterCode.EventForward] = webFlags.WebhookFlags;
            }
            return(client.LoadBalancingPeer.SendOperation(OperationCode.SetProperties, opParameters, sendOptions));
        }
コード例 #14
0
        public static bool SetExpectedUsers(this Room room, HashSet <string> newExpectedUsers, int?newMaxPlayers = null, WebFlags webFlags = null, bool broadcast = true)
        {
            Hashtable hash     = new Hashtable();
            Hashtable expected = new Hashtable();

            if (newMaxPlayers.HasValue)
            {
                hash.Add(GamePropertyKey.MaxPlayers, newMaxPlayers);
                expected.Add(GamePropertyKey.MaxPlayers, room.MaxPlayers);
            }

            if (newExpectedUsers == null)
            {
                hash.Add(GamePropertyKey.ExpectedUsers, null);
            }
            else
            {
                hash.Add(GamePropertyKey.ExpectedUsers, newExpectedUsers.ToArray());
            }

            if (room.ExpectedUsers != null)
            {
                expected.Add(GamePropertyKey.ExpectedUsers, room.ExpectedUsers);
            }

            ParameterDictionary opParameters = new ParameterDictionary(3);

            opParameters.Add(ParameterCode.Properties, hash);
            opParameters.Add(ParameterCode.ExpectedValues, expected);
            if (broadcast)
            {
                opParameters.Add(ParameterCode.Broadcast, true);
            }
            if (webFlags != null)
            {
                opParameters.Add(ParameterCode.EventForward, webFlags.WebhookFlags);
            }
            return(room.LoadBalancingClient.LoadBalancingPeer.SendOperation(OperationCode.SetProperties, opParameters,
                                                                            SendOptions.SendReliable));
        }
コード例 #15
0
        public static bool ReplaceExpectedUser(this Room room, string toRemove, string toAdd, WebFlags webFlags = null, bool broadcast = true)
        {
            if (string.IsNullOrEmpty(toRemove) || string.IsNullOrEmpty(toAdd) || toRemove.Equals(toAdd))
            {
                return(false);
            }

            if (room.ExpectedUsers == null || !room.ExpectedUsers.Contains(toRemove))
            {
                return(false);
            }

            HashSet <string> hashSet = new HashSet <string>(room.ExpectedUsers);

            if (!hashSet.Remove(toRemove))
            {
                return(false);
            }

            if (!hashSet.Add(toAdd))
            {
                return(false);
            }

            return(room.SetExpectedUsers(hashSet, webFlags: webFlags, broadcast: broadcast));
        }
コード例 #16
0
        public static bool AddExpectedUsers(this Room room, string[] userIds, bool force = false, WebFlags webFlags = null, bool broadcast = true)
        {
            if (userIds == null || userIds.Length == 0)
            {
                return(false);
            }

            HashSet <string> hashSet;

            if (room.ExpectedUsers != null)
            {
                hashSet = new HashSet <string>(room.ExpectedUsers);
            }
            else
            {
                hashSet = new HashSet <string>();
            }

            for (int i = 0; i < userIds.Length; i++)
            {
                string userId = userIds[i];
                if (string.IsNullOrEmpty(userId))
                {
                    return(false);
                }

                if (!hashSet.Add(userId))
                {
                    return(false);
                }
            }

            int maxPlayers = room.MaxPlayers;

            if (room.MaxPlayers > 0 && hashSet.Count + room.PlayerCount > room.MaxPlayers)
            {
                if (!room.PublishUserId)
                {
                    return(false);
                }

                int alreadyTaken = 0;
                foreach (string user in hashSet)
                {
                    if (room.Players.Values.Any(player => user.Equals(player.UserId)))
                    {
                        alreadyTaken++;
                    }
                }

                if (hashSet.Count + room.PlayerCount - alreadyTaken > room.MaxPlayers)
                {
                    if (force)
                    {
                        maxPlayers = hashSet.Count + room.PlayerCount - alreadyTaken;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(room.SetExpectedUsers(hashSet, maxPlayers, webFlags, broadcast));
        }
コード例 #17
0
 public static bool RemoveExpectedUser(this Room room, string userId, WebFlags webFlags = null, bool broadcast = true)
 {
     return(!string.IsNullOrEmpty(userId) && room.RemoveExpectedUsers(new[] { userId }, webFlags, broadcast));
 }
コード例 #18
0
        public static bool ChangeExpectedUsers(this Room room, string[] toRemove, string[] toAdd, bool force = false, WebFlags webFlags = null, bool broadcast = true)
        {
            HashSet <string> hashSet = null;

            if (toRemove != null && toRemove.Length > 0)
            {
                if (room.ExpectedUsers == null)
                {
                    return(false);
                }

                if (toRemove.Length > room.ExpectedUsers.Length)
                {
                    return(false);
                }

                hashSet = new HashSet <string>(room.ExpectedUsers);
                for (int i = 0; i < toRemove.Length; i++)
                {
                    string userId = toRemove[i];
                    if (string.IsNullOrEmpty(userId))
                    {
                        return(false);
                    }

                    if (!hashSet.Remove(userId))
                    {
                        return(false);
                    }
                }
            }
            else if (toAdd != null && toAdd.Length > 0)
            {
                if (room.ExpectedUsers == null)
                {
                    hashSet = new HashSet <string>();
                }
                else
                {
                    hashSet = new HashSet <string>(room.ExpectedUsers);
                }
            }
            else
            {
                return(false);
            }

            for (int i = 0; i < toAdd.Length; i++)
            {
                string userId = toAdd[i];
                if (string.IsNullOrEmpty(userId))
                {
                    return(false);
                }

                if (!hashSet.Add(userId))
                {
                    return(false);
                }
            }

            int maxPlayers = room.MaxPlayers;

            if (room.MaxPlayers > 0 && hashSet.Count + room.PlayerCount > room.MaxPlayers)
            {
                if (!room.PublishUserId)
                {
                    return(false);
                }

                int alreadyTaken = 0;
                foreach (string user in hashSet)
                {
                    if (room.Players.Values.Any(player => user.Equals(player.UserId)))
                    {
                        alreadyTaken++;
                    }
                }

                if (hashSet.Count + room.PlayerCount - alreadyTaken > room.MaxPlayers)
                {
                    if (force)
                    {
                        maxPlayers = hashSet.Count + room.PlayerCount - alreadyTaken;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(room.SetExpectedUsers(hashSet, maxPlayers, webFlags, broadcast));
        }
コード例 #19
0
 public static bool AddExpectedUser(this Room room, string userId, bool force = false, WebFlags webFlags = null, bool broadcast = true)
 {
     return(!string.IsNullOrEmpty(userId) && room.AddExpectedUsers(new[] { userId }, force, webFlags, broadcast));
 }