Ejemplo n.º 1
0
        public override void HandleMessage(ClientStructure client, IMessageData messageData)
        {
            var message = messageData as KerbalBaseMsgData;
            switch (message?.KerbalMessageType)
            {
                case KerbalMessageType.Request:
                    var kerbalFiles = FileHandler.GetFilesInPath(Path.Combine(ServerContext.UniverseDirectory, "Kerbals"));
                    var kerbalsData = kerbalFiles.Select(k => new KeyValuePair<string, byte[]>(Path.GetFileNameWithoutExtension(k),
                        FileHandler.ReadFile(k)));

                    LunaLog.Debug($"Sending {client.PlayerName} {kerbalFiles.Length} kerbals...");

                    var newMessageData = new KerbalReplyMsgData
                    {
                        KerbalsData = kerbalsData.ToArray()
                    };

                    MessageQueuer.SendToClient<KerbalSrvMsg>(client, newMessageData);
                    break;
                case KerbalMessageType.Proto:
                    var data = (KerbalProtoMsgData)message;

                    LunaLog.Debug($"Saving kerbal {data.KerbalName} from {client.PlayerName}");

                    var path = Path.Combine(ServerContext.UniverseDirectory, "Kerbals", $"{data.KerbalName}.txt");
                    FileHandler.WriteToFile(path, data.KerbalData);

                    MessageQueuer.RelayMessage<KerbalSrvMsg>(client, data);
                    break;
                default:
                    throw new NotImplementedException("Kerbal type not implemented");
            }
        }
        /// <summary>
        /// We store all the kerbals in the KerbalProtoQueue dictionary so later once the game starts we load them
        /// </summary>
        /// <param name="messageData"></param>
        private static void HandleKerbalReply(KerbalReplyMsgData messageData)
        {
            for (var i = 0; i < messageData.KerbalsCount; i++)
            {
                ProcessKerbal(messageData.Kerbals[i].KerbalData, messageData.Kerbals[i].NumBytes);
            }

            LunaLog.Log("[LMP]: Kerbals Synced!");
            MainSystem.NetworkState = ClientState.KerbalsSynced;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// We store all the kerbals in the KerbalProtoQueue dictionary so later once the game starts we load them
        /// </summary>
        /// <param name="messageData"></param>
        private static void HandleKerbalReply(KerbalReplyMsgData messageData)
        {
            foreach (var kerbal in messageData.KerbalsData)
            {
                var kerbalNode = ConfigNodeSerializer.Singleton.Deserialize(kerbal.Value);
                if (kerbalNode != null)
                {
                    System.KerbalQueue.Enqueue(kerbalNode);
                }
                else
                {
                    Debug.LogError("[LMP]: Failed to load kerbal!");
                }
            }

            Debug.Log("[LMP]: Kerbals Synced!");
            MainSystem.Singleton.NetworkState = ClientState.KERBALS_SYNCED;
        }
        /// <summary>
        /// We store all the kerbals in the KerbalProtoQueue dictionary so later once the game starts we load them
        /// </summary>
        /// <param name="messageData"></param>
        private static void HandleKerbalReply(KerbalReplyMsgData messageData)
        {
            foreach (var kerbal in messageData.KerbalsData)
            {
                var kerbalNode = ConfigNodeSerializer.Deserialize(kerbal.Value);
                if (kerbalNode != null)
                {
                    System.KerbalQueue.Enqueue(kerbalNode);
                }
                else
                {
                    LunaLog.LogError("[LMP]: Failed to load kerbal!");
                }
            }

            LunaLog.Log("[LMP]: Kerbals Synced!");
            SystemsContainer.Get <MainSystem>().NetworkState = ClientState.KerbalsSynced;
        }