Esempio n. 1
0
 protected override void OnAllMembersData(ref AllMembersDataMsg msg)
 {
     if (msg.Clients != null)
     {
         foreach (MyObjectBuilder_Client client in msg.Clients)
         {
             if (!this.m_memberData.ContainsKey(client.SteamId))
             {
                 MyMultiplayerBase.MyConnectedClientData data = new MyMultiplayerBase.MyConnectedClientData {
                     Name    = client.Name,
                     IsAdmin = client.IsAdmin
                 };
                 this.m_memberData.Add(client.SteamId, data);
             }
             if (!this.m_members.Contains(client.SteamId))
             {
                 this.m_members.Add(client.SteamId);
             }
             if (!Sync.Clients.HasClient(client.SteamId))
             {
                 Sync.Clients.AddClient(client.SteamId);
             }
         }
     }
     base.ProcessAllMembersData(ref msg);
 }
Esempio n. 2
0
 private unsafe void OnConnectedClient(ref ConnectedClientDataMsg msg, ulong steamId)
 {
     if (!MyGameService.GameServer.BeginAuthSession(steamId, msg.Token))
     {
         MyLog.Default.WriteLineAndConsole("Authentication failed.");
     }
     else if (!msg.ExperimentalMode && this.ExperimentalMode)
     {
         MyLog.Default.WriteLineAndConsole("Server and client Experimental Mode does not match.");
         this.SendJoinResult(steamId, JoinResult.ExperimentalMode, 0UL);
     }
     else
     {
         base.RaiseClientJoined(steamId);
         MyLog.Default.WriteLineAndConsole("OnConnectedClient " + msg.Name + " attempt");
         if (this.m_members.Contains(steamId))
         {
             MyLog.Default.WriteLineAndConsole("Already joined");
             this.SendJoinResult(steamId, JoinResult.AlreadyJoined, 0UL);
         }
         else if (!MySandboxGame.ConfigDedicated.Banned.Contains(steamId))
         {
             MyMultiplayerBase.MyConnectedClientData *dataPtr1;
             MyMultiplayerBase.MyConnectedClientData  data = new MyMultiplayerBase.MyConnectedClientData {
                 Name = msg.Name
             };
             dataPtr1->IsAdmin = MySandboxGame.ConfigDedicated.Administrators.Contains(steamId.ToString()) || MySandboxGame.ConfigDedicated.Administrators.Contains(ConvertSteamIDFrom64(steamId));
             dataPtr1          = (MyMultiplayerBase.MyConnectedClientData *) ref data;
             this.m_pendingMembers.Add(steamId, data);
         }
         else
         {
             MyLog.Default.WriteLineAndConsole("User is banned by admins");
             ulong result = 0UL;
             foreach (KeyValuePair <ulong, MyMultiplayerBase.MyConnectedClientData> pair in this.m_memberData)
             {
                 if (pair.Value.IsAdmin && (pair.Key != base.ServerId))
                 {
                     result = pair.Key;
                     break;
                 }
             }
             if ((result == 0) && (MySandboxGame.ConfigDedicated.Administrators.Count > 0))
             {
                 ulong.TryParse(MySandboxGame.ConfigDedicated.Administrators[0], out result);
             }
             this.SendJoinResult(steamId, JoinResult.BannedByAdmins, result);
         }
     }
 }
Esempio n. 3
0
 public void LoadMembersFromWorld(List <MyObjectBuilder_Client> clients)
 {
     if (clients != null)
     {
         foreach (MyObjectBuilder_Client client in clients)
         {
             MyMultiplayerBase.MyConnectedClientData data = new MyMultiplayerBase.MyConnectedClientData {
                 Name    = client.Name,
                 IsAdmin = client.IsAdmin
             };
             this.m_memberData.Add(client.SteamId, data);
             base.RaiseClientJoined(client.SteamId);
         }
     }
 }
Esempio n. 4
0
 private void OnConnectedClient(ref ConnectedClientDataMsg msg)
 {
     object[] objArray1 = new object[] { "Client connected: ", msg.Name, " (", msg.SteamID, ")" };
     MySandboxGame.Log.WriteLineAndConsole(string.Concat(objArray1));
     if ((MySandboxGame.IsGameReady && ((msg.SteamID != base.ServerId) && (Sync.MyId != msg.SteamID))) && msg.Join)
     {
         MyHudNotification notification = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 0x1388, "Blue", MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, 0, MyNotificationLevel.Important);
         object[]          arguments    = new object[] { msg.Name };
         notification.SetTextFormatArguments(arguments);
         MyHud.Notifications.Add(notification);
     }
     MyMultiplayerBase.MyConnectedClientData data = new MyMultiplayerBase.MyConnectedClientData {
         Name    = msg.Name,
         IsAdmin = msg.IsAdmin
     };
     this.m_memberData[msg.SteamID] = data;
     base.RaiseClientJoined(msg.SteamID);
 }
Esempio n. 5
0
 protected void MemberDataSet(ulong steamId, MyMultiplayerBase.MyConnectedClientData data)
 {
     this.m_memberData[steamId] = data;
     this.m_gameServerDataDirty = true;
 }
Esempio n. 6
0
 protected bool MemberDataGet(ulong steamId, out MyMultiplayerBase.MyConnectedClientData data) =>
 this.m_memberData.TryGetValue(steamId, out data);
Esempio n. 7
0
 private void MemberDataAdd(ulong steamId, MyMultiplayerBase.MyConnectedClientData data)
 {
     this.m_memberData.Add(steamId, data);
     this.m_gameServerDataDirty = true;
 }
Esempio n. 8
0
        protected void Initialize(IPEndPoint serverEndpoint)
        {
            this.m_groupId     = MySandboxGame.ConfigDedicated.GroupID;
            this.ServerStarted = false;
            this.HostName      = "Dedicated server";
            this.SetMemberLimit(this.MaxPlayers);
            MyGameService.Peer2Peer.SessionRequest   += new Action <ulong>(this.Peer2Peer_SessionRequest);
            MyGameService.Peer2Peer.ConnectionFailed += new Action <ulong, string>(this.Peer2Peer_ConnectionFailed);
            base.ClientLeft += new Action <ulong, MyChatMemberStateChangeEnum>(this.MyDedicatedServer_ClientLeft);
            MyGameService.GameServer.PlatformConnected          += new Action(this.GameServer_ServersConnected);
            MyGameService.GameServer.PlatformConnectionFailed   += new Action <string>(this.GameServer_ServersConnectFailure);
            MyGameService.GameServer.PlatformDisconnected       += new Action <string>(this.GameServer_ServersDisconnected);
            MyGameService.GameServer.PolicyResponse             += new Action <sbyte>(this.GameServer_PolicyResponse);
            MyGameService.GameServer.ValidateAuthTicketResponse += new Action <ulong, JoinResult, ulong>(this.GameServer_ValidateAuthTicketResponse);
            MyGameService.GameServer.UserGroupStatusResponse    += new Action <ulong, ulong, bool, bool>(this.GameServer_UserGroupStatus);
            string serverName = MySandboxGame.ConfigDedicated.ServerName;

            if (string.IsNullOrWhiteSpace(serverName))
            {
                serverName = "Unnamed server";
            }
            MyGameService.GameServer.SetServerName(serverName);
            MyGameService.Peer2Peer.SetServer(true);
            if (MyGameService.GameServer.Start(serverEndpoint, (ushort)MySandboxGame.ConfigDedicated.SteamPort, MyFinalBuildConstants.APP_VERSION.ToString()))
            {
                MyGameService.GameServer.SetModDir(MyPerGameSettings.SteamGameServerGameDir);
                MyGameService.GameServer.ProductName     = MyPerGameSettings.SteamGameServerProductName;
                MyGameService.GameServer.GameDescription = MyPerGameSettings.SteamGameServerDescription;
                MyGameService.GameServer.SetDedicated(true);
                if (!string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.ServerPasswordHash) && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.ServerPasswordSalt))
                {
                    MyGameService.GameServer.SetPasswordProtected(true);
                    this.IsPasswordProtected = true;
                }
                MyGameService.GameServer.LogOnAnonymous();
                MyGameService.GameServer.EnableHeartbeats(true);
                if ((this.m_groupId != 0) && (MyGameService.GetServerAccountType(this.m_groupId) != MyGameServiceAccountType.Clan))
                {
                    MyLog.Default.WriteLineAndConsole("Specified group ID is invalid: " + this.m_groupId);
                }
                uint  ip       = 0;
                ulong serverId = 0UL;
                int   num3     = 100;
                while ((ip == 0) && (num3 > 0))
                {
                    MyGameService.GameServer.Update();
                    Thread.Sleep(100);
                    num3--;
                    ip       = MyGameService.GameServer.GetPublicIP();
                    serverId = MyGameService.GameServer.ServerId;
                }
                MyGameService.UserId = serverId;
                if (ip == 0)
                {
                    MyLog.Default.WriteLineAndConsole("Error: No IP assigned.");
                }
                else
                {
                    IPAddress address = IPAddressExtensions.FromIPv4NetworkOrder(ip);
                    base.ServerId = MyGameService.GameServer.ServerId;
                    base.ReplicationLayer.SetLocalEndpoint(new EndpointId(MyGameService.GameServer.ServerId));
                    this.m_members.Add(base.ServerId);
                    MyMultiplayerBase.MyConnectedClientData data = new MyMultiplayerBase.MyConnectedClientData {
                        Name    = MyTexts.GetString(MySpaceTexts.ChatBotName),
                        IsAdmin = true
                    };
                    this.MemberDataAdd(base.ServerId, data);
                    base.SyncLayer.RegisterClientEvents(this);
                    MyLog.Default.WriteLineAndConsole("Server successfully started");
                    MyLog.Default.WriteLineAndConsole("Product name: " + MyGameService.GameServer.ProductName);
                    MyLog.Default.WriteLineAndConsole("Desc: " + MyGameService.GameServer.GameDescription);
                    MyLog.Default.WriteLineAndConsole("Public IP: " + address.ToString());
                    MyLog.Default.WriteLineAndConsole("Steam ID: " + serverId.ToString());
                    this.ServerStarted = true;
                }
            }
        }