Beispiel #1
0
 protected virtual void RaiseCaughtRecieved(CaughtMessage message)
 {
     if (message.FugitiveClientId == client.SessionId)
     {
         // only dispatch this message if it is intended for this session
         if (CaughtRecieved != null)
         {
             CaughtRecieved(this, new MessageEventArgs <CaughtMessage>(message));
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sends the surrender message
        /// </summary>
        /// <returns><c>true</c>, if surrender was sent, <c>false</c> otherwise.</returns>
        /// <param name="message">Message.</param>
        public bool SendCaughtMessage(CaughtMessage 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);
        }
Beispiel #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);
            }