public virtual void OnNoticeReceived(AVIMNotice notice) { var response = new PlayResponse(notice.RawData); if (response.IsSuccessful) { if (Done != null) { Done(Command, response); } } //Play.LogCommand(Command, null, Play.CommandType.WebSocket); //Play.LogCommand(null, response, Play.CommandType.WebSocket); if (EventCode != PlayEventCode.None) { var next = PlayStateMachine.Next(EventCode, response); if (response.IsSuccessful) { Play.InvokeEvent(next); } else { Play.InvokeEvent(next, response.ErrorCode, response.ErrorReason); } } Play.UnsubscribeNoticeReceived(this); }
internal static void DoUpdateFriends(PlayCommand request, PlayResponse response) { lock (friendListMutex) { var onlineListStr = response.Body["online_list"] as string; var onlineList = onlineListStr.Split(','); } }
public static PlayEventCode Next(PlayEventCode eventCode, PlayResponse response) { if (response.StatusCode > 201 || response.StatusCode < 200) { return(Failed(eventCode)); } else { return(Successed(eventCode)); } }
internal static void DoRejoinRoom(PlayCommand request, PlayResponse response) { if (!response.IsSuccessful) { Play.InvokeEvent(PlayEventCode.OnJoinRoomFailed, response.ErrorCode, response.ErrorReason); return; } var room = GetRoomWhenGet(request, response); Play.InvokeEvent(PlayEventCode.OnJoiningRoom); ConnectRoom(room, true); }
internal static void RunHttpCommand(PlayCommand command, PlayEventCode eventCode = PlayEventCode.None, Action <PlayCommand, PlayResponse> done = null) { if (eventCode != PlayEventCode.None) { Play.InvokeEvent(eventCode); } var httpRequest = command.HttpEncode; Play.ExecuteHttp(httpRequest, (tuple => { int statusCode = (int)HttpStatusCode.BadRequest; IDictionary <string, object> body = new Dictionary <string, object>(); try { body = Json.Parse(tuple.Item2) as IDictionary <string, object>; statusCode = (int)tuple.Item1; } catch { } var response = new PlayResponse() { Body = body as IDictionary <string, object>, StatusCode = (int)tuple.Item1 }; if (response.IsSuccessful) { LogCommand(command, response); if (done != null) { done(command, response); } } else { LogCommand(command, response, printer: ErrorLogger); } if (eventCode != PlayEventCode.None) { var next = PlayStateMachine.Next(eventCode, response); if (response.IsSuccessful) { Play.InvokeEvent(next); } else { Play.InvokeEvent(next, response.ErrorCode, response.ErrorReason); } } })); }
internal static PlayRoom GetRoomWhenGet(PlayCommand request, PlayResponse response) { var room = new PlayRoom(); room.RoomRemoteSecureAddress = response.Body["secureAddr"] as string; room.RoomRemoteAddress = response.Body["addr"] as string; var roomProperties = response.Body; room.SetProperties(roomProperties); return(room); }
/// <summary> /// Fetchs from public cloud. /// </summary> /// <returns>The from public cloud.</returns> /// <param name="response">Response.</param> public static PlayGameServer FetchFromPublicCloud(PlayResponse response) { if (response.IsSuccessful) { return(new PlayGameServer() { FetchedAt = DateTime.Now, Url = response.Body["server"] as string, SecondaryUrl = response.Body["secondary"] as string, TTL = int.Parse(response.Body["ttl"].ToString()), ServiceMode = Mode.Public, ComunicationProtocol = Protocol.WebSokcet }); } return(null); }
internal static void LogCommand(PlayCommand command, PlayResponse response = null, CommandType commandType = CommandType.Http, Action <string> printer = null) { if (printer == null) { printer = Logger; } lock (logMutext) { if (command != null) { IDictionary <string, object> requestDictionary = new Dictionary <string, object>(); if (commandType == CommandType.Http) { requestDictionary.Add("url", command.RelativeUrl); requestDictionary.Add("method", command.Method); requestDictionary.Add("headers", PlayCommand.Headers); requestDictionary.Add("body", command.Body); } else { requestDictionary = command.Body; } var requestId = requestDictionary.ContainsKey("i") ? requestDictionary["i"].ToString() : ""; Print(printer, commandType + " request:" + requestId + "=>" + requestDictionary.ToJsonLog()); } if (response != null) { IDictionary <string, object> responseDictionary = new Dictionary <string, object>(); if (commandType == CommandType.Http) { responseDictionary.Add("statusCode", response.StatusCode); responseDictionary.Add("body", response.Body); } else { responseDictionary = response.Body; } var responseId = responseDictionary.ContainsKey("i") ? responseDictionary["i"].ToString() : ""; Print(printer, commandType + " response:" + responseId + "<=" + responseDictionary.ToJsonLog()); } } }
internal static void DoSetRoomProperties(PlayRoom room, PlayResponse response) { var invalidKeys = new string[] { "cmd", "peerId", "op", "appId", "i" }; room.SetProperties(response.Body.Filter(invalidKeys)); }
internal static void DoLeaveRoom(PlayCommand request, PlayResponse response) { DisconnectRoom(Play.Room); }
private IEnumerable <IDictionary <string, object> > GrabPlayerProperties(PlayResponse response) { return(response.Body as IList <IDictionary <string, object> >); }