internal MyMultiplayerClient(GameServerItem server, MySyncLayer syncLayer) : base(syncLayer) { m_membersCollection = new MemberCollection(m_members); Server = server; ServerId = server.SteamID; SyncLayer.TransportLayer.IsBuffering = true; SyncLayer.RegisterClientEvents(this); SetReplicationLayer(new MyReplicationClient(this, CreateClientState())); syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, OnReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, OnReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, OnReplicationBeginCreate); syncLayer.TransportLayer.Register(MyMessageId.JOIN_RESULT, OnJoinResult); syncLayer.TransportLayer.Register(MyMessageId.WORLD_DATA, OnWorldData); syncLayer.TransportLayer.Register(MyMessageId.WORLD_BATTLE_DATA, OnWorldBattleData); syncLayer.TransportLayer.Register(MyMessageId.CLIENT_CONNNECTED, OnClientConnected); ClientJoined += MyMultiplayerClient_ClientJoined; ClientLeft += MyMultiplayerClient_ClientLeft; HostLeft += MyMultiplayerClient_HostLeft; Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest += Peer2Peer_SessionRequest; m_battleData = new MyMultiplayerBattleData(this); }
public void LoadDataComponents() { RaiseOnLoading(); if (SyncLayer.AutoRegisterGameEvents) { SyncLayer.RegisterGameEvents(); } Sync.Clients.SetLocalSteamId(Sync.MyId, createLocalClient: !(MyMultiplayer.Static is MyMultiplayerClient)); Sync.Players.RegisterEvents(); SetAsNotReady(); HashSet <MySessionComponentBase> processedComponents = new HashSet <MySessionComponentBase>(); do { m_sessionComponents.ApplyChanges(); foreach (var comp in m_sessionComponents.Values) { if (processedComponents.Contains(comp)) { continue; } LoadComponent(comp); processedComponents.Add(comp); } } while (m_sessionComponents.HasChanges()); }
internal MyMultiplayerLobbyClient(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); SyncLayer.TransportLayer.IsBuffering = true; SetReplicationLayer(new MyReplicationClient(this, CreateClientState())); syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, ReplicationLayer.ProcessReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, ReplicationLayer.ProcessReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, ReplicationLayer.ProcessReplicationCreateBegin); Debug.Assert(!IsServer, "Wrong object created"); MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
internal MyMultiplayerLobbyClient(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); if (IsServer) { HostName = MySteam.UserName; } else { SyncLayer.TransportLayer.IsBuffering = true; SetReplicationLayer(new MyReplicationClient(this, new MyClientState())); syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, ReplicationLayer.ProcessReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, ReplicationLayer.ProcessReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); } Debug.Assert(!IsServer, "Wrong object created"); SyncLayer.RegisterMessageImmediate <AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); if (IsServer) { HostName = MySteam.UserName; } else { SyncLayer.TransportLayer.IsBuffering = true; } Debug.Assert(IsServer, "Wrong object created"); SyncLayer.RegisterMessageImmediate <AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
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)) { MyGuiScreenMainMenu.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); SyncLayer.SendMessageToServer(ref msg); }
internal MyMultiplayerClient(GameServerItem server, MySyncLayer syncLayer) : base(syncLayer) { m_membersCollection = new MemberCollection(m_members); Server = server; ServerId = server.SteamID; SyncLayer.TransportLayer.IsBuffering = true; SyncLayer.RegisterClientEvents(this); SetReplicationLayer(new MyReplicationClient(this, CreateClientState(), MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS)); ReplicationLayer.UseSmoothPing = MyFakes.MULTIPLAYER_SMOOTH_PING; ReplicationLayer.UseSmoothCorrection = MyFakes.MULTIPLAYER_SMOOTH_TIMESTAMP_CORRECTION; syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, OnReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, OnReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, OnReplicationBeginCreate); syncLayer.TransportLayer.Register(MyMessageId.JOIN_RESULT, OnJoinResult); syncLayer.TransportLayer.Register(MyMessageId.WORLD_DATA, OnWorldData); syncLayer.TransportLayer.Register(MyMessageId.CLIENT_CONNNECTED, OnClientConnected); ClientJoined += MyMultiplayerClient_ClientJoined; ClientLeft += MyMultiplayerClient_ClientLeft; HostLeft += MyMultiplayerClient_HostLeft; Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest += Peer2Peer_SessionRequest; }
internal MyMultiplayerClient(GameServerItem server, MySyncLayer syncLayer) : base(syncLayer) { m_membersCollection = new MemberCollection(m_members); Server = server; ServerId = server.SteamID; SyncLayer.TransportLayer.IsBuffering = true; SyncLayer.RegisterClientEvents(this); //MySyncLayer.RegisterMessage<ChatMsg>(OnChatMessage, MyMessagePermissions.Any, MyTransportMessageEnum.Request); //MySyncLayer.RegisterMessage<SendServerDataMsg>(OnServerData, MyMessagePermissions.Any, MyTransportMessageEnum.Request); //MySyncLayer.RegisterMessage<ConnectedPlayerDataMsg>(OnPlayerConnected, MyMessagePermissions.Any, MyTransportMessageEnum.Request); RegisterControlMessage <ChatMsg>(MyControlMessageEnum.Chat, OnChatMessage); RegisterControlMessage <ServerDataMsg>(MyControlMessageEnum.ServerData, OnServerData); RegisterControlMessage <JoinResultMsg>(MyControlMessageEnum.JoinResult, OnUserJoined); SyncLayer.RegisterMessageImmediate <ConnectedClientDataMsg>(this.OnConnectedClient, MyMessagePermissions.Any); ClientJoined += MyMultiplayerClient_ClientJoined; ClientLeft += MyMultiplayerClient_ClientLeft; HostLeft += MyMultiplayerClient_HostLeft; Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest += Peer2Peer_SessionRequest; }
internal MyMultiplayerLobbyClient(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); SyncLayer.TransportLayer.IsBuffering = true; SetReplicationLayer(new MyReplicationClient(this, CreateClientState(), MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS)); ReplicationLayer.UseSmoothPing = MyFakes.MULTIPLAYER_SMOOTH_PING; ReplicationLayer.UseSmoothCorrection = MyFakes.MULTIPLAYER_SMOOTH_TIMESTAMP_CORRECTION; syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, ReplicationLayer.ProcessReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, ReplicationLayer.ProcessReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, ReplicationLayer.ProcessReplicationCreateBegin); Debug.Assert(!IsServer, "Wrong object created"); MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
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); }
public void RegisterEvents() { if (SyncLayer.AutoRegisterGameEvents) { SyncLayer.RegisterGameEvents(); } Sync.Clients.SetLocalSteamId(Sync.MyId, createLocalClient: !(MyMultiplayer.Static is MyMultiplayerClient)); Sync.Players.RegisterEvents(); SetAsNotReady(); }
internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer, new EndpointId(Sync.MyId)) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); HostName = MySteam.UserName; Debug.Assert(IsServer, "Wrong object created"); MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
internal MyMultiplayerClient(GameServerItem server, MySyncLayer syncLayer) : base(syncLayer) { m_membersCollection = new MemberCollection(m_members); Server = server; ServerId = server.SteamID; SyncLayer.TransportLayer.IsBuffering = true; SyncLayer.RegisterClientEvents(this); SetReplicationLayer(new MyReplicationClient(this, CreateClientState())); syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, OnReplicationCreate); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, OnReplicationDestroy); syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync); syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, OnReplicationBeginCreate); //MySyncLayer.RegisterMessage<ChatMsg>(OnChatMessage, MyMessagePermissions.Any, MyTransportMessageEnum.Request); //MySyncLayer.RegisterMessage<SendServerDataMsg>(OnServerData, MyMessagePermissions.Any, MyTransportMessageEnum.Request); //MySyncLayer.RegisterMessage<ConnectedPlayerDataMsg>(OnPlayerConnected, MyMessagePermissions.Any, MyTransportMessageEnum.Request); RegisterControlMessage <ChatMsg>(MyControlMessageEnum.Chat, OnChatMessage, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); RegisterControlMessage <ServerDataMsg>(MyControlMessageEnum.ServerData, OnServerData, MyMessagePermissions.FromServer); RegisterControlMessage <JoinResultMsg>(MyControlMessageEnum.JoinResult, OnUserJoined, MyMessagePermissions.FromServer); RegisterControlMessage <ServerBattleDataMsg>(MyControlMessageEnum.BattleData, OnServerBattleData, MyMessagePermissions.FromServer); SyncLayer.RegisterMessageImmediate <ConnectedClientDataMsg>(this.OnConnectedClient, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); SyncLayer.RegisterMessageImmediate <AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); ClientJoined += MyMultiplayerClient_ClientJoined; ClientLeft += MyMultiplayerClient_ClientLeft; HostLeft += MyMultiplayerClient_HostLeft; Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed; Peer2Peer.SessionRequest += Peer2Peer_SessionRequest; m_battleData = new MyMultiplayerBattleData(this); }
internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer) : base(syncLayer) { Lobby = lobby; ServerId = Lobby.GetOwner(); SyncLayer.RegisterClientEvents(this); if (IsServer) { HostName = MySteam.UserName; } else { SyncLayer.TransportLayer.IsBuffering = true; } MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate; MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg; ClientLeft += MyMultiplayerLobby_ClientLeft; AcceptMemberSessions(); }
protected void Initialize(IPEndPoint serverEndpoint) { m_groupId = MySandboxGame.ConfigDedicated.GroupID; ServerStarted = false; HostName = "Dedicated server"; SyncLayer.RegisterMessageImmediate <ConnectedClientDataMsg>(this.OnConnectedClient, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); SyncLayer.RegisterMessageImmediate <AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer); m_membersCollection = new MemberCollection(m_members); SetMemberLimit(MaxPlayers); SteamSDK.Peer2Peer.SessionRequest += Peer2Peer_SessionRequest; SteamSDK.Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed; ClientLeft += MyDedicatedServer_ClientLeft; SteamSDK.SteamServerAPI.Instance.GameServer.ServersConnected += GameServer_ServersConnected; SteamSDK.SteamServerAPI.Instance.GameServer.ServersConnectFailure += GameServer_ServersConnectFailure; SteamSDK.SteamServerAPI.Instance.GameServer.ServersDisconnected += GameServer_ServersDisconnected; SteamSDK.SteamServerAPI.Instance.GameServer.PolicyResponse += GameServer_PolicyResponse; SteamSDK.SteamServerAPI.Instance.GameServer.ValidateAuthTicketResponse += GameServer_ValidateAuthTicketResponse; SteamSDK.SteamServerAPI.Instance.GameServer.UserGroupStatus += GameServer_UserGroupStatus; ServerStartResult startResult = SteamSDK.SteamServerAPI.Instance.GameServer.Start( serverEndpoint, (ushort)MySandboxGame.ConfigDedicated.SteamPort, SteamSDK.ServerMode.eServerModeAuthenticationAndSecure, MyFinalBuildConstants.APP_VERSION.ToString(), MyFakes.DEDICATED_SERVER_USE_SOCKET_SHARE); switch (startResult) { case ServerStartResult.PortAlreadyUsed: ServerInitError = "Error starting Steam dedicated server: Server port " + (ushort)MySandboxGame.ConfigDedicated.ServerPort + " already in use"; MyLog.Default.WriteLineAndConsole(ServerInitError); break; case ServerStartResult.UnknownError: ServerInitError = "Error starting Steam dedicated server"; MyLog.Default.WriteLineAndConsole(ServerInitError); break; } if (startResult != ServerStartResult.OK) { return; } // This has to be exact name of app like this to show in Server Browser SteamSDK.SteamServerAPI.Instance.GameServer.SetModDir(MyPerGameSettings.SteamGameServerGameDir); SteamSDK.SteamServerAPI.Instance.GameServer.ProductName = MyPerGameSettings.SteamGameServerProductName; SteamSDK.SteamServerAPI.Instance.GameServer.GameDescription = MyPerGameSettings.SteamGameServerDescription; SteamSDK.SteamServerAPI.Instance.GameServer.SetDedicated(true); string serverName = MySandboxGame.ConfigDedicated.ServerName; if (String.IsNullOrWhiteSpace(serverName)) { serverName = "Unnamed server"; } SteamSDK.SteamServerAPI.Instance.GameServer.SetServerName(serverName); SteamSDK.SteamServerAPI.Instance.GameServer.LogOnAnonymous(); SteamSDK.SteamServerAPI.Instance.GameServer.EnableHeartbeats(true); if (m_groupId != 0 && SteamServerAPI.Instance.GetAccountType(m_groupId) != AccountType.Clan) { MyLog.Default.WriteLineAndConsole("Specified group ID is invalid: " + m_groupId); } UInt32 ip = 0; UInt64 id = 0; int timeout = 100; while (ip == 0 && timeout > 0) { SteamSDK.SteamServerAPI.Instance.GameServer.RunCallbacks(); Thread.Sleep(100); timeout--; ip = SteamSDK.SteamServerAPI.Instance.GameServer.GetPublicIP(); id = SteamSDK.SteamServerAPI.Instance.GameServer.GetSteamID(); } MySandboxGame.Services.SteamService.UserId = id; if (ip == 0) { MyLog.Default.WriteLineAndConsole("Error: No IP assigned."); return; } var ipAddress = IPAddressExtensions.FromIPv4NetworkOrder(ip); ServerId = MySteam.Server.GetSteamID(); m_members.Add(ServerId); m_memberData.Add(ServerId, new MyConnectedClientData() { Name = "Server", IsAdmin = true }); SyncLayer.RegisterClientEvents(this); MyLog.Default.WriteLineAndConsole("Server successfully started"); MyLog.Default.WriteLineAndConsole("Product name: " + SteamSDK.SteamServerAPI.Instance.GameServer.ProductName); MyLog.Default.WriteLineAndConsole("Desc: " + SteamSDK.SteamServerAPI.Instance.GameServer.GameDescription); MyLog.Default.WriteLineAndConsole("Public IP: " + ipAddress.ToString()); MyLog.Default.WriteLineAndConsole("Steam ID: " + id.ToString()); ServerStarted = true; }