/// <summary>
        /// Initializes a new instance of the MyMultiplayerServerBase class.
        /// </summary>
        /// <param name="localClientEndpoint">Local client endpoint (for single player or lobby host) or null (for dedicated server)</param>
        public MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId? localClientEndpoint)
            : base(syncLayer)
        {
            Debug.Assert(MyEntities.GetEntities().Count == 0, "Multiplayer server must be created before any entities are loaded!");

            var replication = new MyReplicationServer(this, () => MySandboxGame.Static.UpdateTime, localClientEndpoint);
            if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
            {
                replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
            }
            SetReplicationLayer(replication);
            ClientLeft += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));

            MyEntities.OnEntityCreate += CreateReplicableForObject;
            MyEntityComponentBase.OnAfterAddedToContainer += CreateReplicableForObject;
            MyExternalReplicable.Destroyed += DestroyReplicable;

            foreach (var entity in MyEntities.GetEntities())
            {
                CreateReplicableForObject(entity);
                var components = entity.Components;
                if (components != null)
                {
                    foreach (var comp in components)
                        CreateReplicableForObject(comp);
                }
            }

            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, (p) => ClientReady(p));
        }
        public MyMultiplayerServerBase(MySyncLayer syncLayer)
            : base(syncLayer)
        {
            var replication = new MyReplicationServer(this, () => MySandboxGame.Static.UpdateTime);
            if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
            {
                replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
            }
            SetReplicationLayer(replication);
            ClientLeft += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));

            MyEntities.OnEntityCreate += CreateReplicableForObject;
            MyInventory.OnCreated += CreateReplicableForObject;
            MyExternalReplicable.Destroyed += DestroyReplicable;

            foreach (var entity in MyEntities.GetEntities())
            {
                CreateReplicableForObject(entity);
            }

            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, (p) => ReplicationLayer.OnClientReady(p.Sender, new MyClientState()));
        }
示例#3
0
 static MySyncWarhead()
 {
     MySyncLayer.RegisterMessage <SetTimerMsg>(SetTimerRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <SetTimerMsg>(SetTimerSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <CountdownMsg>(CountdownRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <CountdownMsg>(CountdownSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <ArmMsg>(ArmSuccess, MyMessagePermissions.Any);
     MySyncLayer.RegisterMessage <DetonateMsg>(DetonateRequest, MyMessagePermissions.Any);
 }
 static ProductionBlockSync()
 {
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, AddQueueItemMsg>(OnAddQueueItemRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, AddQueueItemMsg>(OnAddQueueItemSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, RemoveQueueItemMsg>(OnRemoveQueueItemRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, RemoveQueueItemMsg>(OnRemoveQueueItemSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, MoveQueueItemMsg>(OnMoveQueueItemRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterEntityMessage <ProductionBlockSync, MoveQueueItemMsg>(OnMoveQueueItemSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
 }
示例#5
0
 static SyncClass()
 {
     MySyncLayer.RegisterMessage <ModeSwitchMsg>(ModeSwitchRequestCallback, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <ModeSwitchMsg>(ModeSwitchSuccessCallback, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <RepeatEnabledMsg>(RepeatEnabledRequestCallback, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <RepeatEnabledMsg>(RepeatEnabledSuccessCallback, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <DisassembleAllMsg>(DisassembleAllRequestCallback, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <SlaveModeSwitchMsg>(SlaveSwitchRequestCallback, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <SlaveModeSwitchMsg>(SlaveSwitchSuccessCallback, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
 }
示例#6
0
 protected MyDedicatedServerBase(MySyncLayer syncLayer) : base(syncLayer, new EndpointId(Sync.MyId))
 {
     this.m_appVersion      = (int)MyFinalBuildConstants.APP_VERSION;
     this.m_members         = new List <ulong>();
     this.m_memberData      = new Dictionary <ulong, MyMultiplayerBase.MyConnectedClientData>();
     this.m_pendingMembers  = new Dictionary <ulong, MyMultiplayerBase.MyConnectedClientData>();
     this.m_waitingForGroup = new HashSet <ulong>();
     this.m_mods            = new List <MyObjectBuilder_Checkpoint.ModItem>();
     syncLayer.TransportLayer.Register(MyMessageId.CLIENT_CONNNECTED, 0xff, new Action <MyPacket>(this.ClientConnected));
 }
示例#7
0
 static MyAiTargetManager()
 {
     MySyncLayer.RegisterMessage <ReserveEntityMsg>(OnReserveEntityRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <ReserveEntityMsg>(OnReserveEntitySuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <ReserveEntityMsg>(OnReserveEntityFailure, MyMessagePermissions.FromServer, MyTransportMessageEnum.Failure);
     MySyncLayer.RegisterMessage <ReserveEnvironmentItemMsg>(OnReserveEnvironmentItemRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <ReserveEnvironmentItemMsg>(OnReserveEnvironmentItemSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <ReserveEnvironmentItemMsg>(OnReserveEnvironmentItemFailure, MyMessagePermissions.FromServer, MyTransportMessageEnum.Failure);
     MySyncLayer.RegisterMessage <ReserveVoxelPositionMsg>(OnReserveVoxelPositionRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <ReserveVoxelPositionMsg>(OnReserveVoxelPositionSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
     MySyncLayer.RegisterMessage <ReserveVoxelPositionMsg>(OnReserveVoxelPositionFailure, MyMessagePermissions.FromServer, MyTransportMessageEnum.Failure);
 }
示例#8
0
 internal MyMultiplayerLobby(IMyLobby lobby, MySyncLayer syncLayer) : base(syncLayer, new EndpointId(Sync.MyId))
 {
     this.m_lobby  = lobby;
     base.ServerId = this.m_lobby.OwnerId;
     base.SyncLayer.RegisterClientEvents(this);
     this.HostName                 = MyGameService.UserName;
     lobby.OnChatUpdated          += new MyLobbyChatUpdated(this.Matchmaking_LobbyChatUpdate);
     lobby.OnChatReceived         += new MessageReceivedDelegate(this.Matchmaking_LobbyChatMsg);
     lobby.OnChatScriptedReceived += new MessageScriptedReceivedDelegate(this.Matchmaking_LobbyChatScriptedMsg);
     lobby.OnDataReceived         += new MyLobbyDataUpdated(this.lobby_OnDataReceived);
     base.ClientLeft              += new Action <ulong, MyChatMemberStateChangeEnum>(this.MyMultiplayerLobby_ClientLeft);
     this.AcceptMemberSessions();
 }
        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();
        }
示例#10
0
 internal MyMultiplayerLobbyClient(IMyLobby lobby, MySyncLayer syncLayer) : base(syncLayer)
 {
     this.Lobby    = lobby;
     base.ServerId = this.Lobby.OwnerId;
     base.SyncLayer.RegisterClientEvents(this);
     base.SyncLayer.TransportLayer.IsBuffering = true;
     if (!base.SyncLayer.Clients.HasClient(base.ServerId))
     {
         base.SyncLayer.Clients.AddClient(base.ServerId);
     }
     base.ClientLeft              += new Action <ulong, MyChatMemberStateChangeEnum>(this.MyMultiplayerLobby_ClientLeft);
     lobby.OnChatUpdated          += new MyLobbyChatUpdated(this.Matchmaking_LobbyChatUpdate);
     lobby.OnChatReceived         += new MessageReceivedDelegate(this.Matchmaking_LobbyChatMsg);
     lobby.OnChatScriptedReceived += new MessageScriptedReceivedDelegate(this.Matchmaking_LobbyChatScriptedMsg);
     lobby.OnDataReceived         += new MyLobbyDataUpdated(this.lobby_OnDataReceived);
     this.AcceptMemberSessions();
 }
示例#11
0
        protected void SendControlMessage <T>(ulong user, ref T message, bool reliable = true) where T : struct
        {
            ITransportCallback   callback;
            MyControlMessageEnum enum2;

            this.m_controlMessageTypes.TryGetValue(typeof(T), out enum2);
            this.m_controlMessageHandlers.TryGetValue((int)enum2, out callback);
            MyControlMessageCallback <T> callback2 = (MyControlMessageCallback <T>)callback;

            if (MySyncLayer.CheckSendPermissions(user, callback2.Permission))
            {
                MyNetworkWriter.MyPacketDescriptor packet = MyNetworkWriter.GetPacketDescriptor(new EndpointId(user), reliable ? MyP2PMessageEnum.ReliableWithBuffering : MyP2PMessageEnum.Unreliable, 0);
                packet.Header.WriteUShort((ushort)enum2);
                callback2.Write(packet.Header, ref message);
                MyNetworkWriter.SendPacket(packet);
            }
        }
示例#12
0
 void ITransportCallback.Receive(ByteStream source, ulong sender)
 {
     if (MySyncLayer.CheckReceivePermissions(sender, this.Permission))
     {
         TMsg local;
         try
         {
             this.m_serializer.Deserialize(source, out local);
         }
         catch (Exception exception)
         {
             MySandboxGame.Log.WriteLine(new Exception($"Error deserializing '{typeof(TMsg).Name}', message size '{source.Length}'", exception));
             return;
         }
         this.m_callback(ref local, sender);
     }
 }
示例#13
0
 internal MyMultiplayerBase(MySyncLayer syncLayer)
 {
     this.SyncLayer              = syncLayer;
     this.IsConnectionDirect     = true;
     this.IsConnectionAlive      = true;
     this.m_kickedClients        = new ConcurrentDictionary <ulong, int>();
     this.m_bannedClients        = new MyConcurrentHashSet <ulong>();
     this.m_wrongPasswordClients = new Dictionary <ulong, int>();
     this.m_lastKickUpdate       = MySandboxGame.TotalTimeInMilliseconds;
     MyNetworkMonitor.Init();
     MyNetworkReader.SetHandler(0, new NetworkMessageDelegate(this.ControlMessageReceived), new Action <ulong>(this.DisconnectClient));
     this.RegisterControlMessage <MyControlKickClientMsg>(MyControlMessageEnum.Kick, new ControlMessageHandler <MyControlKickClientMsg>(this.OnClientKick), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlDisconnectedMsg>(MyControlMessageEnum.Disconnected, new ControlMessageHandler <MyControlDisconnectedMsg>(this.OnDisconnectedClient), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlBanClientMsg>(MyControlMessageEnum.Ban, new ControlMessageHandler <MyControlBanClientMsg>(this.OnClientBan), MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
     this.RegisterControlMessage <MyControlSendPasswordHashMsg>(MyControlMessageEnum.SendPasswordHash, new ControlMessageHandler <MyControlSendPasswordHashMsg>(this.OnPasswordHash), MyMessagePermissions.ToServer);
     syncLayer.TransportLayer.DisconnectPeerOnError = new Action <ulong>(this.DisconnectClient);
     this.ClientKicked += new Action <ulong>(this.KickClient);
 }
示例#14
0
 internal MyMultiplayerClient(MyGameServerItem server, MySyncLayer syncLayer) : base(syncLayer)
 {
     this.m_members    = new List <ulong>();
     this.m_memberData = new Dictionary <ulong, MyMultiplayerBase.MyConnectedClientData>();
     this.m_mods       = new List <MyObjectBuilder_Checkpoint.ModItem>();
     base.SyncLayer.RegisterClientEvents(this);
     base.SyncLayer.TransportLayer.IsBuffering = true;
     this.Server      = server;
     base.ServerId    = server.SteamID;
     base.ClientLeft += new Action <ulong, MyChatMemberStateChangeEnum>(this.MyMultiplayerClient_ClientLeft);
     syncLayer.TransportLayer.Register(MyMessageId.JOIN_RESULT, 0, new Action <MyPacket>(this.OnJoinResult));
     syncLayer.TransportLayer.Register(MyMessageId.WORLD_DATA, 0, new Action <MyPacket>(this.OnWorldData));
     syncLayer.TransportLayer.Register(MyMessageId.CLIENT_CONNNECTED, 0, new Action <MyPacket>(this.OnClientConnected));
     base.ClientJoined += new Action <ulong>(this.MyMultiplayerClient_ClientJoined);
     base.HostLeft     += new Action(this.MyMultiplayerClient_HostLeft);
     MyGameService.Peer2Peer.ConnectionFailed += new Action <ulong, string>(this.Peer2Peer_ConnectionFailed);
     MyGameService.Peer2Peer.SessionRequest   += new Action <ulong>(this.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);

            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 MyMultiplayerBase(MySyncLayer syncLayer)
        {
            SyncLayer              = syncLayer;
            m_controlSendStream    = new ByteStream(64 * 1024, true);
            m_controlReceiveStream = new ByteStream();

            m_kickedClients = new Dictionary <ulong, int>();
            m_bannedClients = new HashSet <ulong>();

            m_lastKickUpdate = MySandboxGame.TotalTimeInMilliseconds;

            MyNetworkReader.SetHandler(MyMultiplayer.ControlChannel, ControlMessageReceived);

            RegisterControlMessage <MyControlWorldRequestMsg>(MyControlMessageEnum.WorldRequest, OnWorldRequest);
            RegisterControlMessage <MyControlAckMessageMsg>(MyControlMessageEnum.Ack, OnAck);
            RegisterControlMessage <MyControlKickClientMsg>(MyControlMessageEnum.Kick, OnClientKick);
            RegisterControlMessage <MyControlDisconnectedMsg>(MyControlMessageEnum.Disconnected, OnDisconnectedClient);
            RegisterControlMessage <MyControlBanClientMsg>(MyControlMessageEnum.Ban, OnClientBan);
            RegisterControlMessage <MyControlPingMsg>(MyControlMessageEnum.Ping, OnPing);
            //m_serializers[typeof(MyControlMessageData)] = new XmlSerializer(typeof(MyControlMessageData));
        }
示例#17
0
        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();
        }
        /// <summary>
        /// Initializes a new instance of the MyMultiplayerServerBase class.
        /// </summary>
        /// <param name="localClientEndpoint">Local client endpoint (for single player or lobby host) or null (for dedicated server)</param>
        public MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId?localClientEndpoint)
            : base(syncLayer)
        {
            Debug.Assert(MyEntities.GetEntities().Count == 0, "Multiplayer server must be created before any entities are loaded!");

            var replication = new MyReplicationServer(this, localClientEndpoint, MyFakes.MULTIPLAYER_USE_PLAYOUT_DELAY_BUFFER);

            if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
            {
                replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
            }
            SetReplicationLayer(replication);
            ClientLeft   += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));
            ClientJoined += (steamId) => ReplicationLayer.OnClientJoined(new EndpointId(steamId), CreateClientState());

            MyEntities.OnEntityCreate += CreateReplicableForObject;
            MyEntityComponentBase.OnAfterAddedToContainer += CreateReplicableForObject;
            MyExternalReplicable.Destroyed += DestroyReplicable;

            foreach (var entity in MyEntities.GetEntities())
            {
                CreateReplicableForObject(entity);
                var components = entity.Components;
                if (components != null)
                {
                    foreach (var comp in components)
                    {
                        CreateReplicableForObject(comp);
                    }
                }
            }

            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_ACKS, ReplicationLayer.OnClientAcks);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, ClientReady);
        }
示例#19
0
        public static MyMultiplayerHostResult HostLobby(LobbyTypeEnum lobbyType, int maxPlayers, MySyncLayer syncLayer)
        {
            System.Diagnostics.Debug.Assert(syncLayer != null);
            MyTrace.Send(TraceWindow.Multiplayer, "Host game");

            MyMultiplayerHostResult ret = new MyMultiplayerHostResult();
            SteamSDK.Lobby.Create(lobbyType, maxPlayers, (lobby, result) =>
            {
                if (!ret.Cancelled)
                {
                    if (result == Result.OK && lobby.GetOwner() != MySteam.UserId)
                    {
                        result = Result.Fail;
                        lobby.Leave();
                    }

                    MyTrace.Send(TraceWindow.Multiplayer, "Lobby created");
                    lobby.SetLobbyType(lobbyType);
                    ret.RaiseDone(result, result == Result.OK ? MyMultiplayer.Static = new MyMultiplayerLobby(lobby, syncLayer) : null);
                }
            });
            return ret;
        }
示例#20
0
        void ITransportCallback.Receive(ByteStream source, ulong sender, TimeSpan timestamp)
        {
            if (!MySyncLayer.CheckReceivePermissions(sender, Permission))
            {
                return;
            }

            TMsg msg;

            try
            {
                Serializer.Deserialize(source, out msg);
                MyTrace.Send(TraceWindow.Multiplayer, "Received control message: " + msg.ToString(), sender + ", " + source.Position + " B");
            }
            catch (Exception e)
            {
                // Catch, add more info (what message) and write to log
                MySandboxGame.Log.WriteLine(new Exception(String.Format("Error deserializing '{0}', message size '{1}'", typeof(TMsg).Name, source.Length), e));
                return;
            }

            Callback(ref msg, sender);
        }
示例#21
0
        internal MyMultiplayerBase(MySyncLayer syncLayer)
        {
            SyncLayer              = syncLayer;
            m_controlSendStream    = new ByteStream(64 * 1024, true);
            m_controlReceiveStream = new ByteStream();

            m_kickedClients = new Dictionary <ulong, int>();
            m_bannedClients = new HashSet <ulong>();

            m_lastKickUpdate = MySandboxGame.TotalTimeInMilliseconds;

            MyNetworkReader.SetHandler(MyMultiplayer.ControlChannel, ControlMessageReceived);

            RegisterControlMessage <MyControlWorldRequestMsg>(MyControlMessageEnum.WorldRequest, OnWorldRequest, MyMessagePermissions.ToServer);
            RegisterControlMessage <MyControlAckMessageMsg>(MyControlMessageEnum.Ack, OnAck, MyMessagePermissions.ToServer);
            RegisterControlMessage <MyControlKickClientMsg>(MyControlMessageEnum.Kick, OnClientKick, MyMessagePermissions.FromServer | MyMessagePermissions.ToServer);
            RegisterControlMessage <MyControlDisconnectedMsg>(MyControlMessageEnum.Disconnected, OnDisconnectedClient, MyMessagePermissions.FromServer | MyMessagePermissions.ToServer);
            RegisterControlMessage <MyControlBanClientMsg>(MyControlMessageEnum.Ban, OnClientBan, MyMessagePermissions.FromServer | MyMessagePermissions.ToServer);
            RegisterControlMessage <MyControlPingMsg>(MyControlMessageEnum.Ping, OnPing, MyMessagePermissions.FromServer | MyMessagePermissions.ToServer);
            //m_serializers[typeof(MyControlMessageData)] = new XmlSerializer(typeof(MyControlMessageData));

            // TODO: Remove
            //SyncLayer.TransportLayer.Register(MyMessageId.SERVER_UPDATE, OnServerPhysicsUpdate);
        }
示例#22
0
 static MySyncCameraBlock()
 {
     MySyncLayer.RegisterEntityMessage <MySyncCameraBlock, ChangeFovMsg>(OnChangeFovRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterEntityMessage <MySyncCameraBlock, ChangeFovMsg>(OnChangeFovSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
 }
        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 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);
        }
示例#25
0
        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();
        }
        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();
        }
示例#27
0
        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();
        }
 protected MyDedicatedServerBase(MySyncLayer syncLayer)
     : base(syncLayer)
 {
 }
示例#29
0
 static SyncClass()
 {
     MySyncLayer.RegisterMessage <UseMsg>(UseRequest, MyMessagePermissions.ToServer, MyTransportMessageEnum.Request);
     MySyncLayer.RegisterMessage <UseMsg>(UseSuccess, MyMessagePermissions.FromServer, MyTransportMessageEnum.Success);
 }
 protected MyDedicatedServerBase(MySyncLayer syncLayer)
     : base(syncLayer, null)
 {
     syncLayer.TransportLayer.Register(MyMessageId.CLIENT_CONNNECTED, (p) => ClientConnected(p));
 }
示例#31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySession"/> class.
        /// </summary>
        private MySession(MySyncLayer syncLayer, bool registerComponents = true)
        {
            Debug.Assert(syncLayer != null);

            if (syncLayer == null)
                MyLog.Default.WriteLine("MySession.Static.MySession() - sync layer is null");

            SyncLayer = syncLayer;

            ElapsedGameTime = new TimeSpan();

            // To reset spectator positions
            Spectator.Reset();

            m_timeOfSave = MyTimeSpan.Zero;
            ElapsedGameTime = new TimeSpan();

            Ready = false;
            MultiplayerLastMsg = 0;
            MultiplayerAlive = true;
            MultiplayerDirect = true;

            AppVersionFromSave = MyFinalBuildConstants.APP_VERSION;

            Factions.FactionStateChanged += OnFactionsStateChanged;

            ScriptManager = new MyScriptManager();

            GC.Collect(2, GCCollectionMode.Forced);
            MySandboxGame.Log.WriteLine(String.Format("GC Memory: {0} B", GC.GetTotalMemory(false).ToString("##,#")));
            MySandboxGame.Log.WriteLine(String.Format("Process Memory: {0} B", Process.GetCurrentProcess().PrivateMemorySize64.ToString("##,#")));

            this.GameFocusManager = new MyGameFocusManager();

        }
示例#32
0
 static MySyncAirVent()
 {
     MySyncLayer.RegisterEntityMessage <MySyncAirVent, ChangeDepressurizationModeMsg>(OnStockipleModeChanged, MyMessagePermissions.Any);
     MySyncLayer.RegisterEntityMessage <MySyncAirVent, ChangeToolbarItemMsg>(OnToolbarItemChanged, MyMessagePermissions.Any);
 }
示例#33
0
        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();
        }
 protected MyDedicatedServerBase(MySyncLayer syncLayer)
     : base(syncLayer)
 {
     RegisterControlMessage<ChatMsg>(MyControlMessageEnum.Chat, OnChatMessage, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
 }
示例#35
0
        internal void RegisterControlMessage <T>(MyControlMessageEnum msg, ControlMessageHandler <T> handler, MyMessagePermissions permission) where T : struct
        {
            MyControlMessageCallback <T> callback = new MyControlMessageCallback <T>(handler, MySyncLayer.GetSerializer <T>(), permission);

            m_controlMessageHandlers.Add((int)msg, callback);
            m_controlMessageTypes.Add(typeof(T), 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()));
            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);
        }
 protected MyDedicatedServerBase(MySyncLayer syncLayer)
     : base(syncLayer)
 {
     RegisterControlMessage <ChatMsg>(MyControlMessageEnum.Chat, OnChatMessage, MyMessagePermissions.ToServer | MyMessagePermissions.FromServer);
 }
示例#38
0
 static MyGuiBlueprintScreen()
 {
     MySyncLayer.RegisterMessage <ShareBlueprintMsg>(ShareBlueprintRequest, MyMessagePermissions.Any);
 }
示例#39
0
 static MySyncButtonPanel()
 {
     MySyncLayer.RegisterEntityMessage <MySyncButtonPanel, CheckAccessMsg>(OnCheckAccessChanged, MyMessagePermissions.Any);
     MySyncLayer.RegisterEntityMessage <MySyncButtonPanel, ChangeToolbarItemMsg>(OnToolbarItemChanged, MyMessagePermissions.Any);
     MySyncLayer.RegisterEntityMessage <MySyncButtonPanel, SetCustomButtonName>(OnButtonCustomNameChanged, MyMessagePermissions.Any);
 }
示例#40
0
        public static MyMultiplayerHostResult HostLobby(LobbyTypeEnum lobbyType, int maxPlayers, MySyncLayer syncLayer)
        {
            System.Diagnostics.Debug.Assert(syncLayer != null);
            MyTrace.Send(TraceWindow.Multiplayer, "Host game");

            MyMultiplayerHostResult ret = new MyMultiplayerHostResult();

#if !XB1
            SteamSDK.Lobby.Create(lobbyType, maxPlayers, (lobby, result) =>
            {
                if (!ret.Cancelled)
                {
                    if (result == Result.OK && lobby.GetOwner() != Sync.MyId)
                    {
                        result = Result.Fail;
                        lobby.Leave();
                    }

                    MyTrace.Send(TraceWindow.Multiplayer, "Lobby created");
                    lobby.SetLobbyType(lobbyType);
                    ret.RaiseDone(result, result == Result.OK ? MyMultiplayer.Static = new MyMultiplayerLobby(lobby, syncLayer) : null);
                }
            });
#endif
            return(ret);
        }
        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();
        }
 static MySyncPrefabManager()
 {
     MySyncLayer.RegisterMessage <SpawnPrefabMsg>(OnPrefabSpawned, MyMessagePermissions.FromServer);
 }
示例#43
0
 static MySyncOxygenGenerator()
 {
     MySyncLayer.RegisterEntityMessage <MySyncOxygenGenerator, ChangeAutoRefillMsg>(OnAutoRefillChanged, MyMessagePermissions.Any);
     MySyncLayer.RegisterEntityMessage <MySyncOxygenGenerator, RefillRequestMsg>(OnRefillRequest, MyMessagePermissions.ToServer);
 }
 static MySpaceRespawnComponent()
 {
     MySyncLayer.RegisterMessage <SyncCooldownRequestMessage>(OnSyncCooldownRequest, MyMessagePermissions.ToServer);
     MySyncLayer.RegisterMessage <SyncCooldownResponseMessage>(OnSyncCooldownResponse, MyMessagePermissions.FromServer);
 }
示例#45
0
 private MySession(MySyncLayer syncLayer, bool registerComponents = true)
 {
     // Dummy replacement for the Sandbox.Game.World.MySession constructor of the same parameters.
     // So we can create it without getting involed with Havok and other depdancies.
 }