private void OnAuthenticateConnection(NetworkMessage netMsg) { var uconn = UnityNetworkingData.Connections.Find(c => c.ConnectionId == netMsg.conn.connectionId); if (uconn != null) { var message = netMsg.ReadMessage <AuthTicketMessage>(); uconn.PlayFabId = message.PlayFabId; UnityNetworkingEvents.ClientAuthenticated(ClientAuthEventType.TicketReceived, netMsg, message.PlayFabId); Logger.Dispatch(LoggerTypes.Info, string.Format("Auth Received: PlayFabId:{0} AuthTicket:{1}", message.PlayFabId, message.AuthTicket)); if (!message.IsLocal) { PlayFabServerAPI.RedeemMatchmakerTicket(new RedeemMatchmakerTicketRequest() { Ticket = message.AuthTicket, LobbyId = ServerSettingsData.GameId.ToString() }, OnAuthUserResponse, (error) => { Debug.Log(error.GenerateErrorReport()); }); } else { PlayFabServerAPI.AuthenticateSessionTicket(new AuthenticateSessionTicketRequest() { SessionTicket = message.AuthTicket }, OnAuthLocalUserResponse, (error) => { Debug.Log(error.GenerateErrorReport()); }); } } }
private void OnAuthUserResponse(RedeemMatchmakerTicketResult response) { Logger.Dispatch(LoggerTypes.Info, string.Format("PlayFab Says AuthTicket isValid:{0}", response.TicketIsValid)); var uconn = UnityNetworkingData.Connections.Find(c => c.PlayFabId == response.UserInfo.PlayFabId); if (uconn != null) { uconn.IsAuthenticated = response.TicketIsValid; uconn.Connection.Send(201, new StringMessage() { value = "Client Authenticated Successfully" }); UnityNetworkingEvents.ClientAuthenticated(ClientAuthEventType.Validated, null, response.UserInfo.PlayFabId); } }
public override void MapBindings(ICommandBinder commandBinder, ICrossContextInjectionBinder injectionBinder, IMediationBinder mediationBinder) { var _logger = injectionBinder.GetInstance <LogSignal>(); var _serverSettings = injectionBinder.GetInstance <ServerSettingsData>(); _networkService = new UnityNetworkingService(Settings, _serverSettings, _logger); _networkEvents = new UnityNetworkingEvents(); //Bind Settings Object injectionBinder.Bind <UnityNetworkingData>().ToValue(Settings).ToSingleton().CrossContext(); injectionBinder.Bind <UnityNetworkingService>().ToValue(_networkService).ToSingleton().CrossContext(); injectionBinder.Bind <UnityNetworkingEvents>().ToValue(_networkEvents).ToSingleton().CrossContext(); //Bind Mediators to Views mediationBinder.Bind <UnityNetworkManagerView>().To <UnityNetworkManagerMediator>(); }
// called when a client disconnects private void OnServerDisconnect(NetworkMessage netMsg) { if (UnityNetworkingData.ConnectedClients - 1 >= 0) { UnityNetworkingData.ConnectedClients--; } if (UnityNetworkingData.ConnectedClients == 0) { StartCoroutine(CheckForConnectionsOrClose()); } var connection = UnityNetworkingData.Connections.Find(c => c.ConnectionId == netMsg.conn.connectionId); if (connection != null) { if (connection.IsAuthenticated && ServerSettingsData.GameId > 0) { PlayFabServerAPI.NotifyMatchmakerPlayerLeft(new NotifyMatchmakerPlayerLeftRequest() { PlayFabId = connection.PlayFabId, LobbyId = ServerSettingsData.GameId.ToString() }, (playerLeftResponse) => { UnityNetworkingEvents.ClientDisconnected(connection.ConnectionId, connection.PlayFabId); Logger.Dispatch(LoggerTypes.Info, string.Format("Player Has Left:{0}", connection.PlayFabId)); UnityNetworkingData.Connections.Remove(connection); }, (error) => { Debug.Log(error.GenerateErrorReport()); }); } else { UnityNetworkingEvents.ClientDisconnected(connection.ConnectionId, connection.PlayFabId); UnityNetworkingData.Connections.Remove(connection); } } else { UnityNetworkingEvents.ClientDisconnected(netMsg.conn.connectionId, null); } Logger.Dispatch(LoggerTypes.Info, "A Unity Client Disconnected"); }
// called when a client connects private void OnServerConnect(NetworkMessage netMsg) { UnityNetworkingData.ConnectedClients++; UnityNetworkingData.Connections.Add(new UnityNetworkingData.UnityNetworkConnection() { Connection = netMsg.conn, ConnectionId = netMsg.conn.connectionId, LobbyId = ServerSettingsData.GameId.ToString(), IsAuthenticated = false }); //Security: //Give them 30 seconds to authenticate or close the connection. StartCoroutine(CheckForUnauthenticatedClients(netMsg.conn.connectionId)); UnityNetworkingEvents.ClientConnected(netMsg); Logger.Dispatch(LoggerTypes.Info, "A Unity Client Connected"); }