예제 #1
0
        public void Disconnect()
        {
            MDLog.Info(LOG_CAT, "Disconnected from server");
            IsSessionStarted = false;
            foreach (int PeerId in Players.Keys)
            {
                MDPlayerInfo Player = Players[PeerId];
                OnPlayerLeftEvent(PeerId);
                Player.RemoveAndFree();
            }

            NetworkedMultiplayerENet peer = GetPeer();

            if (peer != null)
            {
                peer.CloseConnection();
                SetNetworkPeer(null);
            }

            StopUPNP();
            Players.Clear();
            ClearNetworkedNodes();
            OnSessionEndedEvent();
            SceneBuffer.Clear();
        }
예제 #2
0
        private void GenerateConfigFile(string Source, string Target)
        {
            string existingTarget = FindFile(Target);

            if (existingTarget == "")
            {
                string SourceFilePath = FindFile(Source);
                File   SourceFile     = new File();
                SourceFile.Open(SourceFilePath, File.ModeFlags.Read);
                string SourceText = SourceFile.GetAsText();
                SourceFile.Close();

                if (SourceText == "")
                {
                    MDLog.Error(LOG_CAT, $"Failed to read config from {SourceFilePath}");
                    return;
                }

                string TargetFilePath = $"res://{Target}";
                File   TargetFile     = new File();
                TargetFile.Open(TargetFilePath, File.ModeFlags.Write);

                TargetFile.StoreString(SourceText);
                TargetFile.Close();

                MDLog.Info(LOG_CAT, $"Copied config file from {SourceFilePath} to {TargetFilePath}");
            }
            else
            {
                MDLog.Info(LOG_CAT, $"Config file {existingTarget} already exists");
            }
        }
예제 #3
0
 /// <summary>
 /// Disposes the profiler
 /// </summary>
 public void Dispose()
 {
     Timer.Stop();
     if (_enabledProfiles.Contains(LowerProfileName) || MDArguments.HasArg(LOG_ARG))
     {
         MDLog.Info(LOG_CAT, $"Profiling [{ProfileName}] took {GetMicroSeconds()} us");
     }
 }
예제 #4
0
        private void ClientOnConnected()
        {
            MDLog.Info(LOG_CAT, "Client connected to server");
            int PeerId = MDStatics.GetPeerId();

            OnPlayerJoined_Internal(PeerId);
            OnSessionStartedEvent();
            IsSessionStarted = true;
        }
 public MDGameSynchPeerInfo(MDGameSynchronizer GameSynchronizer, int PeerId)
 {
     MDLog.AddLogCategoryProperties(LOG_CAT, new MDLogProperties(MDLogLevel.Info));
     MDLog.Info(LOG_CAT, $"Creating MDGameSynchPeerInfo for Peer [ID: {PeerId}]");
     this.GameSynchronizer         = GameSynchronizer;
     this.PeerId                   = PeerId;
     this.SettingAveragePingToKeep = GameSynchronizer.GetPingsToKeepForAverage();
     this.CompletedNodeSynch       = false;
     this.CompletedSynch           = false;
     StartMSecCycle();
 }
예제 #6
0
        /// <summary>
        /// Initialize UPNP
        /// </summary>
        /// <param name="Port">The port</param>
        /// <returns>The UPNP object</returns>
        protected UPNP InitUPNP(int Port)
        {
            UPNP NewUPNP = new UPNP();

            UPNP.UPNPResult DiscoverResult = (UPNP.UPNPResult)NewUPNP.Discover();
            MDLog.Info(LOG_CAT, $"UPNP Result for Discover is {DiscoverResult}");
            UPNP.UPNPResult MappingResult = (UPNP.UPNPResult)NewUPNP.AddPortMapping(Port);
            MDLog.Info(LOG_CAT, $"UPNP Result for Mapping Port {Port} is {MappingResult}");
            ExternalAddress = NewUPNP.QueryExternalAddress();
            MDLog.Info(LOG_CAT, $"UPNP External address found [{ExternalAddress}]");
            return(NewUPNP);
        }
예제 #7
0
        public override void _Notification(int NotificationType)
        {
            base._Notification(NotificationType);

            switch (NotificationType)
            {
            case MainLoop.NotificationWmQuitRequest:
                MDLog.Info(LOG_CAT, "Quit notification received.");
                GameSession?.Disconnect();
                break;
            }
        }
예제 #8
0
        public bool StartStandalone()
        {
            MDLog.Info(LOG_CAT, "Starting Standalone Game Session");
            OnPlayerJoined_Internal(STANDALONE_ID);
            MDPlayerInfo PlayerInfo = GetPlayerInfo(STANDALONE_ID);

            if (PlayerInfo != null)
            {
                PlayerInfo.BeginInitialization();
            }
            OnSessionStartedEvent();
            IsSessionStarted = true;
            return(true);
        }
예제 #9
0
        // Called on the server when a client connects
        private void ServerOnPeerConnected(int PeerId)
        {
            MDLog.Info(LOG_CAT, $"Peer [ID: {PeerId}] connected");
            OnPlayerJoined_Internal(PeerId);

            MDPlayerInfo PlayerInfo = GetPlayerInfo(PeerId);

            if (PlayerInfo != null)
            {
                PlayerInfo.BeginInitialization();
            }

            SynchronizeCurrentPlayers(PeerId);
            BroadcastNewPlayerJoined(PeerId);
            SynchronizeNetworkedNodes(PeerId);
        }
예제 #10
0
        private void ServerOnStarted()
        {
            if (GameInstance.UseUPNP())
            {
                ServerUPNP = InitUPNP(UPNPPort);
            }

            MDLog.Info(LOG_CAT, "Server started");
#if !GODOT_SERVER
            OnPlayerJoined_Internal(SERVER_ID);
            MDPlayerInfo PlayerInfo = GetPlayerInfo(SERVER_ID);
            if (PlayerInfo != null)
            {
                PlayerInfo.BeginInitialization();
            }
#endif
            OnSessionStartedEvent();
            IsSessionStarted = true;
        }
예제 #11
0
 // Called on the server when a client disconnects
 private void ServerOnPeerDisconnected(int PeerId)
 {
     MDLog.Info(LOG_CAT, $"Peer [ID: {PeerId}] disconnected");
     OnPlayerLeft_Internal(PeerId);
     BroadcastPlayerLeft(PeerId);
 }
예제 #12
0
        /// <summary>
        /// Call a registered command via its name
        /// </summary>
        /// <param name="Command">The command to call</param>
        /// <returns>True if executed, false if not</returns>
        public static bool InvokeCommand(string Command)
        {
            string[] Args = Command.Split(" ", false);
            if (Args.Length == 0)
            {
                // empty string
                return(false);
            }

            MDLog.Info(LOG_CAT, Command);
            AddCommandToHistory(Command);

            string CmdName = Args[0].ToLower();

            if (!_commandMap.ContainsKey(CmdName))
            {
                MDLog.Error(LOG_CAT, $"Command not found: [{Command}]");
                return(false);
            }

            CommandInfo CmdInfo = _commandMap[CmdName];

            ParameterInfo[] Params = CmdInfo.Method.GetParameters();
            object[]        ParamArray;

            // Should we use the default args?
            if (Params.Length > 0 && Args.Length == 1 && CmdInfo.DefaultArgs.Length == Params.Length)
            {
                ParamArray = CmdInfo.DefaultArgs;
            }
            else
            {
                if (Args.Length - 1 != Params.Length)
                {
                    // Wrong number of arguments
                    return(false);
                }

                ParamArray = new object[Args.Length - 1];
                Array.Copy(Args, 1, ParamArray, 0, ParamArray.Length);
            }

            // Convert the strings to the appropriate type
            List <object> CmdParams = new List <object>();
            int           ArgIndex  = 0;

            foreach (ParameterInfo ParamInfo in Params)
            {
                if (ParamInfo.ParameterType.IsEnum)
                {
                    object Param = Enum.Parse(ParamInfo.ParameterType, ParamArray[ArgIndex++] as string, true);
                    CmdParams.Add(Param);
                }
                else
                {
                    object Param = Convert.ChangeType(ParamArray[ArgIndex++], ParamInfo.ParameterType);
                    CmdParams.Add(Param);
                }
            }

            CmdInfo.Method.Invoke(CmdInfo.Instance, CmdParams.ToArray());

            return(true);
        }
예제 #13
0
 private void ClientOnServerDisconnect()
 {
     MDLog.Info(LOG_CAT, "Client was disconnected from server");
     Disconnect();
 }