예제 #1
0
 public void OnServer(string eventName, ServerEventDelegate serverEventDelegate)
 {
     if (serverEventDelegate == null)
     {
         return;
     }
     if (eventDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent))
     {
         eventHandlersForEvent.Add(serverEventDelegate);
     }
     else
     {
         eventHandlersForEvent = new HashSet <ServerEventDelegate> {
             serverEventDelegate
         };
         eventDelegateHandlers[eventName] = eventHandlersForEvent;
     }
 }
예제 #2
0
 internal static extern void CSharpResourceImpl_SetServerEventDelegate(IntPtr resource,
                                                                       ServerEventDelegate @delegate);
예제 #3
0
 public static void OnServer(string eventName, ServerEventDelegate serverEventDelegate)
 {
     Module.OnServer(eventName, serverEventDelegate);
 }
예제 #4
0
    public void StartServer(NetworkMode _NetworkMode, int _ConnectionCountMax, int _ConnectPort, string _ServerName,
		ServerEventDelegate _ServerStartedDelegate, ServerEventDelegate _ServerStoppedDelegate,
		ServerConnectionDelegate _ClientConnectedDelegate, ServerConnectionDelegate _ClientDisconnectedDelegate)
    {
        Debug.Log("Starting Server...");

        System.Diagnostics.Debug.Assert(Network.peerType == NetworkPeerType.Disconnected);
        System.Diagnostics.Debug.Assert(CanStartServer());

        bool useNatPunchThrough = (_NetworkMode == NetworkMode.E_NetworkOnlineOnly) && !Network.HavePublicAddress();

        m_PublicServerName = _ServerName;

        m_NetworkMode = _NetworkMode;
        m_ConnectionCountMax = _ConnectionCountMax;
        m_ConnectPort = _ConnectPort;
        m_IsUsingNatPunchThrough = useNatPunchThrough;

        m_ServerStartedDelegate = _ServerStartedDelegate;
        m_ServerStoppedDelegate = _ServerStoppedDelegate;
        m_ClientConnectedDelegate = _ClientConnectedDelegate;
        m_ClientDisconnectedDelegate = _ClientDisconnectedDelegate;

        ChangeServerState(ServerState.E_ServerPendingStart);

        NetworkConnectionError initServerResult = Network.InitializeServer(_ConnectionCountMax, _ConnectPort, useNatPunchThrough);
        if (initServerResult != NetworkConnectionError.NoError)
        {
            Debug.Log("Init Server failed:" + initServerResult + " (port: " + _ConnectPort + ")" );

            //@TODO reset member variables
        }
    }
예제 #5
0
    void OnServerInitialized()
    {
        Debug.Log("Server initialized");
        System.Diagnostics.Debug.Assert(Network.isServer);
        System.Diagnostics.Debug.Assert(m_ServerState == ServerState.E_ServerPendingStart);

        ChangeServerState(ServerState.E_ServerStarted);

        if (m_ServerStartedDelegate != null)
        {
            m_ServerStartedDelegate();
            m_ServerStartedDelegate = null;
        }
    }
예제 #6
0
    void OnDisconnectedFromServer(NetworkDisconnection _NetDisconnectionInfo)
    {
        Debug.Log("Server connection disconnected: " + _NetDisconnectionInfo.ToString());
        Debug.Log("Current network peer type is " + Network.peerType.ToString());

        m_ServerStartedDelegate = null;
        m_ServerStoppedDelegate = null;
        m_ClientConnectedDelegate = null;
        m_ClientDisconnectedDelegate = null;

        StopServerAdvertising();

        ChangeServerState(ServerState.E_ServerStopped);

        if (m_ServerStoppedDelegate != null)
        {
            m_ServerStoppedDelegate();
            m_ServerStoppedDelegate = null;
        }
    }
예제 #7
0
    public void StopServer(int _DisconnectTimeOutInMilliseconds)
    {
        Debug.Log("Stopping Server...");

        ChangeServerState(ServerState.E_ServerPendingStop);

        m_ServerStartedDelegate = null;
        m_ServerStoppedDelegate = null;
        m_ClientConnectedDelegate = null;
        m_ClientDisconnectedDelegate = null;

        StopServerAdvertising();

        //@FIXME: nothing provided in Unity3d Network API to specifically stop the server
        Network.Disconnect(_DisconnectTimeOutInMilliseconds);
    }
예제 #8
0
 internal static extern void CSharpResource_SetMain(IntPtr resourcePointer, MainDelegate mainDelegate,
                                                    StopDelegate stopDelegate,
                                                    TickDelegate tickDelegate, ServerEventDelegate serverEventDelegate,
                                                    CheckpointDelegate checkpointDelegate,
                                                    ClientEventDelegate clientEventDelegate, PlayerDamageDelegate playerDamageDelegate,
                                                    PlayerConnectDelegate playerConnectDelegate, PlayerDeathDelegate playerDeathDelegate,
                                                    PlayerDisconnectDelegate playerDisconnectDelegate, PlayerRemoveDelegate playerRemoveDelegate,
                                                    VehicleRemoveDelegate vehicleRemoveDelegate,
                                                    PlayerChangeVehicleSeatDelegate playerChangeVehicleSeatDelegate,
                                                    PlayerEnterVehicleDelegate playerEnterVehicleDelegate,
                                                    PlayerLeaveVehicleDelegate playerLeaveVehicleDelegate,
                                                    CreatePlayerDelegate createPlayerDelegate, RemovePlayerDelegate removePlayerDelegate,
                                                    CreateVehicleDelegate createVehicleDelegate, RemoveVehicleDelegate removeVehicleDelegate,
                                                    CreateBlipDelegate createBlipDelegate, RemoveBlipDelegate removeBlipDelegate,
                                                    CreateCheckpointDelegate createCheckpointDelegate, RemoveCheckpointDelegate removeCheckpointDelegate,
                                                    CreateVoiceChannelDelegate createVoiceChannelDelegate,
                                                    RemoveVoiceChannelDelegate removeVoiceChannelDelegate,
                                                    ConsoleCommandDelegate consoleCommandDelegate,
                                                    MetaDataChange metaDataChange,
                                                    MetaDataChange syncedMetaDataChange,
                                                    CreateColShapeDelegate createColShapeDelegate,
                                                    RemoveColShapeDelegate removeColShapeDelegate,
                                                    ColShapeDelegate colShapeDelegate
                                                    );