예제 #1
0
        static Protocol.RoomOptions ConvertToRoomOptions(string roomName, RoomOptions options, List <string> expectedUserIds)
        {
            var roomOptions = new Protocol.RoomOptions();

            if (!string.IsNullOrEmpty(roomName))
            {
                roomOptions.Cid = roomName;
            }
            if (options != null)
            {
                roomOptions.Visible      = options.Visible;
                roomOptions.Open         = options.Open;
                roomOptions.EmptyRoomTtl = options.EmptyRoomTtl;
                roomOptions.PlayerTtl    = options.PlayerTtl;
                roomOptions.MaxMembers   = options.MaxPlayerCount;
                roomOptions.Flag         = options.Flag;
                if (options.CustomRoomProperties != null)
                {
                    roomOptions.Attr = ByteString.CopyFrom(CodecUtils.SerializePlayObject(options.CustomRoomProperties));
                }
                if (options.CustomRoomPropertyKeysForLobby != null)
                {
                    roomOptions.LobbyAttrKeys.AddRange(options.CustomRoomPropertyKeysForLobby);
                }
                if (options.PluginName != null)
                {
                    roomOptions.PluginName = options.PluginName;
                }
            }
            if (expectedUserIds != null)
            {
                roomOptions.ExpectMembers.AddRange(expectedUserIds);
            }
            return(roomOptions);
        }
예제 #2
0
            public static byte[] Serialize(object obj)
            {
                Weapon weapon     = obj as Weapon;
                var    playObject = new PlayObject {
                    { "name", weapon.Name },
                    { "attack", weapon.Attack }
                };

                return(CodecUtils.SerializePlayObject(playObject));
            }
예제 #3
0
            public static byte[] Serialize(object obj)
            {
                Hero hero       = obj as Hero;
                var  playObject = new PlayObject {
                    { "name", hero.Name },
                    { "score", hero.Score },
                    { "hp", hero.Hp },
                    { "mp", hero.Mp },
                    { "weapons", new PlayArray(hero.Weapons) }
                };

                return(CodecUtils.SerializePlayObject(playObject));
            }
예제 #4
0
        internal async Task <PlayObject> SetRoomCustomProperties(PlayObject properties, PlayObject expectedValues)
        {
            var request = NewRequest();

            request.UpdateProperty = new UpdatePropertyRequest {
                Attr = ByteString.CopyFrom(CodecUtils.SerializePlayObject(properties))
            };
            if (expectedValues != null)
            {
                request.UpdateProperty.ExpectAttr = ByteString.CopyFrom(CodecUtils.SerializePlayObject(expectedValues));
            }
            var res = await SendRequest(CommandType.Conv, OpType.Update, request);

            var props = CodecUtils.DeserializePlayObject(res.Response.UpdateProperty.Attr);

            return(props);
        }
예제 #5
0
        internal async Task <Tuple <int, PlayObject> > SetPlayerCustomProperties(int playerId, PlayObject properties, PlayObject expectedValues)
        {
            var request = NewRequest();

            request.UpdateProperty = new UpdatePropertyRequest {
                TargetActorId = playerId,
                Attr          = ByteString.CopyFrom(CodecUtils.SerializePlayObject(properties))
            };
            if (expectedValues != null)
            {
                request.UpdateProperty.ExpectAttr = ByteString.CopyFrom(CodecUtils.SerializePlayObject(expectedValues));
            }
            var res = await SendRequest(CommandType.Conv, OpType.UpdatePlayerProp, request);

            var actorId = res.Response.UpdateProperty.ActorId;
            var props   = CodecUtils.DeserializePlayObject(res.Response.UpdateProperty.Attr);

            return(new Tuple <int, PlayObject>(actorId, props));
        }
예제 #6
0
        internal Task SendEvent(byte eventId, PlayObject eventData, SendEventOptions options)
        {
            var direct = new DirectCommand {
                EventId = eventId
            };

            if (eventData != null)
            {
                direct.Msg = ByteString.CopyFrom(CodecUtils.SerializePlayObject(eventData));
            }
            direct.ReceiverGroup = (int)options.ReceiverGroup;
            if (options.TargetActorIds != null)
            {
                direct.ToActorIds.AddRange(options.TargetActorIds);
            }
            _ = Send(CommandType.Direct, OpType.None, new Body {
                Direct = direct
            });
            return(Task.FromResult(true));
        }