Ejemplo n.º 1
0
 void SendClientData(ulong steamTo, ulong connectedSteamID, string connectedClientName, bool join)
 {
     ConnectedClientDataMsg msg = new ConnectedClientDataMsg();
     msg.SteamID = connectedSteamID;
     msg.Name = connectedClientName;
     msg.IsAdmin = MySandboxGame.ConfigDedicated.Administrators.Contains(connectedSteamID.ToString()) || MySandboxGame.ConfigDedicated.Administrators.Contains(ConvertSteamIDFrom64(connectedSteamID));
     msg.Join = join;
     SyncLayer.SendMessage(ref msg, steamTo);
 }
Ejemplo n.º 2
0
        void OnConnectedClient(ref ConnectedClientDataMsg msg, MyNetworkClient sender)
        {
            MyLog.Default.WriteLineAndConsole("OnConnectedClient " + msg.Name + " attempt");
            System.Diagnostics.Debug.Assert(msg.Join);

            if (m_members.Contains(msg.SteamID))
            {
                MyLog.Default.WriteLineAndConsole("Already joined");
                SendJoinResult(msg.SteamID, JoinResult.AlreadyJoined);
                return;
            }

            if (MySandboxGame.ConfigDedicated.Banned.Contains(msg.SteamID))
            {
                MyLog.Default.WriteLineAndConsole("User is banned by admins");

                ulong adminID = 0;
                foreach (var user in m_memberData)
                {
                    if (user.Value.IsAdmin)
                    {
                        adminID = user.Key;
                        break;
                    }
                }

                if (adminID == 0 && MySandboxGame.ConfigDedicated.Administrators.Count > 0)
                {
                    adminID = ConvertSteamIDTo64(MySandboxGame.ConfigDedicated.Administrators[0]);
                }


                SendJoinResult(msg.SteamID, JoinResult.BannedByAdmins, adminID);
                return;
            }

            AuthSessionResponseEnum res = SteamSDK.SteamServerAPI.Instance.GameServer.BeginAuthSession(msg.SteamID, msg.Token);
            if (res != AuthSessionResponseEnum.OK)
            {
                MyLog.Default.WriteLineAndConsole("Authentication failed (" + res.ToString() + ")");
                SendJoinResult(msg.SteamID, JoinResult.TicketInvalid);
                return;
            }

            m_pendingMembers.Add(msg.SteamID, new MyConnectedClientData()
            {
                Name = msg.Name,
                IsAdmin = MySandboxGame.ConfigDedicated.Administrators.Contains(msg.SteamID.ToString()) || MySandboxGame.ConfigDedicated.Administrators.Contains(ConvertSteamIDFrom64(msg.SteamID)),
            });
        }
Ejemplo n.º 3
0
        protected void OnConnectedClient(ref ConnectedClientDataMsg msg)
        {
            MySandboxGame.Log.WriteLineAndConsole("Client connected: " + msg.Name + " (" + msg.SteamID.ToString() + ")");
            MyTrace.Send(TraceWindow.Multiplayer, "Client connected");

            if (MySandboxGame.IsGameReady && msg.SteamID != ServerId &&  Sync.MyId != msg.SteamID && msg.Join)
            {
                var clientConnected = new MyHudNotification(MyCommonTexts.NotificationClientConnected, 5000, level: MyNotificationLevel.Important);
                clientConnected.SetTextFormatArguments(msg.Name);
                MyHud.Notifications.Add(clientConnected);
            }

            m_memberData[msg.SteamID] = new MyConnectedClientData()
                {
                    Name = msg.Name,
                    IsAdmin = msg.IsAdmin
                };

            RaiseClientJoined(msg.SteamID);
        }
Ejemplo n.º 4
0
        public void SendPlayerData(string clientName)
        {
            ConnectedClientDataMsg msg = new ConnectedClientDataMsg();
            msg.SteamID = Sync.MyId;
            msg.Name = clientName;
            msg.Join = true;

            var buffer = new byte[1024];
            uint length;
            uint ticketHandle; // TODO: Store handle and end auth session on end
            if (!MySteam.API.GetAuthSessionTicket(out ticketHandle, buffer, out length))
            {
                MySessionLoader.UnloadAndExitToMenu();
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                    messageText: MyTexts.Get(MyCommonTexts.MultiplayerErrorConnectionFailed)));
                return;
            }

            msg.Token = new byte[length];
            Array.Copy(buffer, msg.Token, length);

            ReplicationLayer.SendClientConnected(ref msg);
        }
Ejemplo n.º 5
0
 public void SendClientConnected(ref ConnectedClientDataMsg msg)
 {
     m_sendStream.ResetWrite();
     VRage.Serialization.MySerializer.Write <ConnectedClientDataMsg>(m_sendStream, ref msg);
     m_callback.SendConnectRequest(m_sendStream);
 }