internal void Save(Hashtable propertiesToUpdateOrSet = null, Hashtable expectedValues = null) { if (this.Name == null) { return; } var updateCommand = new PlayCommand(); updateCommand.Body = new Dictionary <string, object>(); updateCommand.Body["cmd"] = "conv"; updateCommand.Body["cid"] = this.Name; updateCommand.Body["op"] = "update"; if (expectedValues != null) { if (propertiesToUpdateOrSet != null) { IDictionary <string, object> casAttr = new Dictionary <string, object>(); expectedValues.Every(kv => { var key = kv.Key; if (propertiesToUpdateOrSet.ContainsKey(key)) { IDictionary <string, object> cas = new Dictionary <string, object>(); var toUpdateValue = propertiesToUpdateOrSet[key]; cas.Add("expect", kv.Value); cas.Add("value", toUpdateValue); casAttr.Add(key.ToString(), cas); } }); updateCommand.Body["casAttr"] = casAttr; } } else { if (propertiesToUpdateOrSet != null) { updateCommand.Body["attr"] = propertiesToUpdateOrSet.ToDictionary(); } else { updateCommand.Body["attr"] = this.EncodeAttributes(); } } Play.RunSocketCommand(updateCommand, done: (request, response) => { lock (this.metaDataMutex) { response.Body.GetValue <IDictionary <string, object> >("attr", null); IDictionary <string, object> attr = response.Body.GetValue <IDictionary <string, object> >("attr", null); this.CustomPropertiesMetaData.Merge(attr); } }); base.Save(); }
internal static void ExecuteRPC(PlayRpcMessage rpcMessage) { var rpcCommand = new PlayCommand(); rpcCommand.Body = new Dictionary <string, object>(); rpcCommand.Body["cmd"] = "direct"; rpcCommand.Body["cid"] = Room.Name; rpcCommand.Body["msg"] = rpcMessage.Serialize(); rpcCommand.Body["echo"] = rpcMessage.Echo; rpcCommand.Body["cached"] = rpcMessage.Cached; rpcCommand.Body["toPeerIds"] = rpcMessage.ToPeers; Play.RunSocketCommand(rpcCommand); }
public void ConnectGameServer() { Play.DoConnectToGameSever(Play.GameServer, () => { var sessionOpenCmd = new PlayCommand() { Body = new Dictionary <string, object>() { { "cmd", "session" }, { "op", "open" }, { "ua", Play.PlayVersion + "_" + Play.GameVersion }, { "peerId", this.ID } } }; Play.RunSocketCommand(sessionOpenCmd, PlayEventCode.OnAuthenticating, done: (req, res) => { this.SessionToken = res.Body["st"] as string; }); }); }
internal void SessionOpen(Action sessionOpened = null) { var sessionCommand = new PlayCommand() { Body = new Dictionary <string, object>() { { "cmd", "session" }, { "op", "open" }, { "ua", Play.PlayVersion + "_" + Play.GameVersion }, { "st", SessionToken } } }; Play.RunSocketCommand(sessionCommand, done: (req, response) => { if (sessionOpened != null) { sessionOpened(); } }); }
internal void SessionRoomJoin(PlayRoom room, bool isRejoin = false, Action <PlayRoom, PlayResponse> roomJoined = null) { var joinCommand = new PlayCommand() { Body = new Dictionary <string, object>() { { "cmd", "conv" }, { "op", "add" }, { "cid", room.Name }, } }; if (isRejoin) { joinCommand.Body.Add("rejoin", isRejoin); } Play.RunSocketCommand(joinCommand, done: (req, response) => { if (roomJoined != null) { roomJoined(room, response); } }); }
internal override void Save(IDictionary <string, object> increment) { var updateCommand = new PlayCommand() { Body = new Dictionary <string, object>() { { "cmd", "conv" }, { "op", "update-player-prop" }, { "cid", Play.Room.Name }, { "targetClientId", this.UserID }, { "playerProperty", increment } } }; Play.RunSocketCommand(updateCommand, done: (request, response) => { if (response.IsSuccessful) { //IDictionary<string, object> results = response.Body["results"] as IDictionary<string, object>; //this.MergeFromServer(results); //Play.InvokeEvent(PlayEventCode.OnPlayerCustomPropertiesChanged, this, results.ToHashtable()); } }); }
internal void SessionCreateRoom(string roomName, PlayRoom.RoomConfig roomConfig, Action <PlayRoom> roomCreated = null) { IDictionary <string, object> body = new Dictionary <string, object>(); if (roomConfig.CustomRoomProperties != null) { body.Add("attr", roomConfig.CustomRoomProperties.ToDictionary()); } if (roomConfig.MaxPlayerCount > 0 && roomConfig.MaxPlayerCount != PlayRoom.DefaultMaxPlayerCount) { body.Add("maxMembers", roomConfig.MaxPlayerCount); } if (roomConfig.EmptyTimeToLive > 0 && roomConfig.EmptyTimeToLive != PlayRoom.DefaultMaxEmptyTimeToLive) { body.Add("emptyRoomTtl", roomConfig.EmptyTimeToLive); } if (roomConfig.PlayerTimeToKeep > 0 && roomConfig.PlayerTimeToKeep != PlayRoom.DefaultMaxKeepPlayerTime) { body.Add("playerTtl", roomConfig.PlayerTimeToKeep); } if (roomConfig.ExpectedUsers != null) { body.Add("expectMembers", roomConfig.ExpectedUsers); } if (!roomConfig.IsVisible) { body.Add("visible", roomConfig.IsVisible); } if (!roomConfig.IsOpen) { body.Add("open", roomConfig.IsOpen); } if (roomConfig.LobbyMatchKeys != null) { body.Add("lobbyAttrKeys", roomConfig.LobbyMatchKeys); } body.Add("cmd", "conv"); body.Add("op", "start"); body.Add("cid", roomName); var createCommand = new PlayCommand() { Body = body }; Play.RunSocketCommand(createCommand, done: (req, response) => { if (response.IsSuccessful) { var room = new PlayRoom(roomConfig, roomName); Play.DoSetRoomProperties(room, response); if (roomCreated != null) { roomCreated(room); } } else { Play.InvokeEvent(PlayEventCode.OnCreateRoomFailed, response.ErrorCode, response.ErrorReason); } }); }