Example #1
0
 bool IPluginHost.SetGameState(SerializableGameState state)
 {
     if (!this.allowSetGameState)
     {
         Log.ErrorFormat("Plugin {0} tries to set game state after call to 'Continue'. Game '{1}', stack\n{2}",
             this.Plugin.Name, this.Name, GetCallStack());
         return false;
     }
     return this.RoomState.SetState(state);
 }
Example #2
0
        public bool SetState(SerializableGameState state)
        {
            this.ActorsManager.ActorNumberCounter = state.ActorCounter;
            if (state.ActorList != null)
            {
                this.ActorsManager.DeserializeActors(state.ActorList);
            }

            if (!this.SetGameStateUencodedBinaryPart(state.Binary))
            {
                return false;
            }

            // - we now inlcude all properties in the binary state
            // - and decided it was confusing to loose type information
            // - so this filed is only for "Info" purposes
            // - only ignoring for now.

            this.CheckUserOnJoin = state.CheckUserOnJoin;
            this.DeleteCacheOnLeave = state.DeleteCacheOnLeave;

            this.EmptyRoomLiveTime = state.EmptyRoomTTL;
            this.IsOpen = state.IsOpen;
            this.IsVisible = state.IsVisible;
            this.PublishUserId = state.PublishUserId;

            this.LobbyId = state.LobbyId;
            this.LobbyType = (AppLobbyType)state.LobbyType;
            if (state.LobbyProperties != null)
            {
                this.LobbyProperties = new HashSet<object>(state.LobbyProperties.ToArray());
            }

            this.MaxPlayers = state.MaxPlayers;

            this.PlayerTTL = state.PlayerTTL;
            this.SuppressRoomEvents = state.SuppressRoomEvents;
            this.EventCache.Slice = state.Slice;

            this.Properties.Set((byte) GameParameter.MasterClientId, 0);

            this.ActorsManager.ExcludedActors = state.ExcludedActors ?? new List<ExcludedActorInfo>();
            this.ActorsManager.ExpectedUsers = state.ExpectedUsers ?? new List<string>();
            return true;
        }
Example #3
0
        public bool SetState(Dictionary<string, object> state)
        {
            if (state.Keys.Contains("0"))
            {
                Log.ErrorFormat("Old style of serializaed data are used");
                return false;
            }

            var serializedState = new SerializableGameState();

            foreach (var entry in state)
            {
                // TBD - improve performance using a Dictionary<String,YourEnum>,
                // see http://stackoverflow.com/questions/16100/how-do-i-convert-a-string-to-an-enum-in-c
                HiveHostGameState key;
                try
                {
                    key = (HiveHostGameState)Enum.Parse(typeof(HiveHostGameState), entry.Key, false);
                }
                catch (ArgumentException)
                {
                    continue;
                }

                switch (key)
                {
                    case HiveHostGameState.ActorCounter:
            //                        this.ActorsManager.ActorNumberCounter = (int)entry.Value;
                        serializedState.ActorCounter = (int) entry.Value;
                        break;
                    case HiveHostGameState.ActorList:
                    {
                        //var list = entry.Value as IList;
                        //this.ActorsManager.DeserializeActors(list);
                        var list = entry.Value as IList;

                        serializedState.ActorList = list.Cast<Dictionary<string, object>>().Select(d => d.ToSerializableActor()).ToList();
                    }
                        break;
                    case HiveHostGameState.CustomProperties:
                        // TBD - we now inlcude all properties in the binary state
                        //     - and decided it was confusing to loose type information
                        //     - so this filed is only for "Info" purposes
                        //     - only ignoring for now.
                        // this.Properties.SetProperties((IDictionary)entry.Value);
                        break;
                    case HiveHostGameState.CheckUserOnJoin:
                        //this.CheckUserOnJoin = (bool)entry.Value;
                        serializedState.CheckUserOnJoin = (bool) entry.Value;
                        break;
                    case HiveHostGameState.DeleteCacheOnLeave:
                        //this.DeleteCacheOnLeave = (bool)entry.Value;
                        serializedState.DeleteCacheOnLeave = (bool) entry.Value;
                        break;
                    case HiveHostGameState.EmptyRoomTTL:
            //                        this.EmptyRoomLiveTime = (int)entry.Value;
                        serializedState.EmptyRoomTTL = (int)entry.Value;
                        break;
                    case HiveHostGameState.IsOpen:
            //                        this.IsOpen = (bool)entry.Value;
                        serializedState.IsOpen = (bool)entry.Value;
                        break;
                    case HiveHostGameState.IsVisible:
                        //this.IsVisible = (bool)entry.Value;
                        serializedState.IsVisible = (bool)entry.Value;
                        break;
                    case HiveHostGameState.LobbyId:
                        serializedState.LobbyId = (string)entry.Value;
            //                        this.LobbyId = (string)entry.Value;
                        break;
                    case HiveHostGameState.LobbyType:
                        serializedState.LobbyType = (int)(AppLobbyType)entry.Value;
            //                        this.LobbyType = (AppLobbyType)entry.Value;
                        break;
                    case HiveHostGameState.LobbyProperties:
                        //var lobbyProperties = entry.Value as ArrayList;
                        //if (lobbyProperties != null)
                        //{
                        //    this.LobbyProperties = new HashSet<object>((lobbyProperties).ToArray());
                        //}
                        serializedState.LobbyProperties = entry.Value as ArrayList;
                        break;
                    case HiveHostGameState.MaxPlayers:
            //                        this.MaxPlayers = Convert.ToByte(entry.Value);
                        serializedState.MaxPlayers = Convert.ToByte(entry.Value);
                        break;
                    case HiveHostGameState.PlayerTTL:
            //                        this.PlayerTTL = (int)entry.Value;
                        serializedState.PlayerTTL = (int)entry.Value;
                        break;
                    case HiveHostGameState.SuppressRoomEvents:
            //                        this.SuppressRoomEvents = (bool)entry.Value;
                        serializedState.SuppressRoomEvents = (bool)entry.Value;
                        break;
                    case HiveHostGameState.Slice:
                        serializedState.Slice = (int)entry.Value;
            //                        this.EventCache.Slice = (int)entry.Value;
                        break;
                    case HiveHostGameState.Binary:
                        //var uencodedBinaryState = (Dictionary<string, object>)entry.Value;
                        //this.SetGameStateUencodedBinaryPart(uencodedBinaryState);
                        serializedState.Binary = (Dictionary<string, object>)entry.Value;
                        break;
                }
            }

            return SetState(serializedState);
        }
Example #4
0
        public SerializableGameState GetSerializableGameState()
        {
            const bool withDebugInfo = true;

            Dictionary<string, object> customProperties;
            ArrayList lobbyProperties;
            var properties = PrepareProperties(out customProperties, out lobbyProperties);

            Dictionary<byte, ArrayList> actorGroups = null;
            int evCount;
            Dictionary<int, ArrayList> events;
            var binary = GetBinaryPartOfGameState(properties, ref actorGroups, out evCount, out events);

            var state = new SerializableGameState
            {
                ActorCounter = this.ActorsManager.ActorNumberCounter,
                ActorList = this.ActorsManager.SerializeActors(withDebugInfo),
                CheckUserOnJoin = this.CheckUserOnJoin,
                CustomProperties = customProperties,
                DeleteCacheOnLeave = this.DeleteCacheOnLeave,
                EmptyRoomTTL = this.EmptyRoomLiveTime,
                IsOpen = this.IsOpen,
                IsVisible = this.IsVisible,
                LobbyId = this.LobbyId,
                LobbyType = (int) this.LobbyType,
                LobbyProperties = lobbyProperties,
                MaxPlayers = this.MaxPlayers,
                PlayerTTL = this.PlayerTTL,
                SuppressRoomEvents = this.SuppressRoomEvents,
                Slice = this.EventCache.Slice,
                Binary = binary,
                ExcludedActors = this.actorsManager.ExcludedActors,
                ExpectedUsers = this.ActorsManager.ExpectedUsers,

            };

            if (withDebugInfo)
            {
                state.DebugInfo = new Dictionary<string, object>();
                if (properties.Count > 0)
                {
                    state.DebugInfo.Add("DEBUG_PROPERTIES_18", properties);
                }
                if (evCount > 0)
                {
                    state.DebugInfo.Add("DEBUG_EVENTS_19", events);
                }
                if (actorGroups != null && actorGroups.Count > 0)
                {
                    state.DebugInfo.Add("DEBUG_GROUPS_20", actorGroups);
                }
            }

            return state;
        }