コード例 #1
0
 protected virtual void RaiseFugutiveLocationRecieved(FugitiveLocationMessage message)
 {
     if (FugutiveLocationRecieved != null)
     {
         FugutiveLocationRecieved(this, new MessageEventArgs <FugitiveLocationMessage>(message));
     }
 }
コード例 #2
0
        /// <summary>
        /// Sends the fugitive location.
        /// </summary>
        /// <returns><c>true</c>, if fugitive location was sent, <c>false</c> otherwise.</returns>
        /// <param name="message">Message.</param>
        public bool SendFugitiveLocation(FugitiveLocationMessage message)
        {
            EnsureUsername(message);

            if (client.IsConnected && client.IsSubscribed(Channel))
            {
                string data = System.Web.HttpUtility.UrlEncode(JsonConvert.SerializeObject(message));
                client.Send(Channel, data);
            }
            else
            {
                throw new Exception("not connected. Call Join Game first");
            }
            return(true);
        }
コード例 #3
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                JToken jObject = JToken.ReadFrom(reader);
                var    type    = jObject["MessageType"].ToString();

                BaseMessage message;

                switch (type)
                {
                case "FugitiveDistance":
                    message = new FugitiveDistanceMessage();
                    break;

                case "FugitiveLocation":
                    message = new FugitiveLocationMessage();
                    break;

                case "GameStartsAt":
                    message = new GameStartsAtMessage();
                    break;

                case "HelloMessage":
                    message = new HelloMessage();
                    break;

                case "Surrender":
                    message = new SurrenderMessage();
                    break;

                case "CaughtMessage":
                    message = new CaughtMessage();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                serializer.Populate(jObject.CreateReader(), message);

                return(message);
            }