Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using Mirror;
- using Insight;
- public class CNetworkManager : NetworkManager
- {
- private NetworkClient networkClient;
- public string UniqueID;
- private ServerAuthentication serverAuthentication;
- private ClientAuthentication clientAuthentication;
- private GameObject insightServer;
- private GameObject insightClient;
- private NetworkConnection ClientConn;
- private NetworkConnection ServerConn;
- public override void Awake()
- {
- base.Awake();
- insightServer = GameObject.FindWithTag("InsightClient");
- insightClient = GameObject.FindWithTag("InsightServer");
- serverAuthentication = insightServer.GetComponentInChildren<ServerAuthentication>();
- clientAuthentication = insightClient.GetComponentInChildren<ClientAuthentication>();
- }
- public override void OnStartClient(NetworkClient client)
- {
- if (LogFilter.Debug) { Debug.Log("OnStartClient()"); }
- base.OnStartClient(client);
- networkClient = client;
- RegisterClientHandlers();
- }
- void RegisterClientHandlers()
- {
- ClientConn.RegisterHandler((short)MsgId.AuthCodeRequestMsg, HandleAuthCodeRequest);
- }
- public void HandleAuthCodeRequest(NetworkMessage netMsg)
- {
- AuthCodeRequestMsg msg = netMsg.ReadMessage<AuthCodeRequestMsg>();
- ClientConn.Send((short)MsgId.AuthCodeResponsMsg, new AuthCodeResponsMsg() { UniqueID = UniqueID });
- }
- //Player Connects to Server
- public override void OnServerConnect(NetworkConnection conn)
- {
- ServerConn = conn;
- if (LogFilter.Debug) { Debug.Log("OnServerConnect()"); }
- base.OnServerConnect(conn); //Tells the client to connect to the correct scene
- //Request AuthCode
- if (LogFilter.Debug) { print("Requesting AuthCode"); }
- ServerConn.Send((short)MsgId.AuthCodeRequestMsg, new AuthCodeRequestMsg());
- RegisterServerHandlers();
- }
- void RegisterServerHandlers()
- {
- NetworkServer.RegisterHandler((short)MsgId.AuthCodeResponsMsg, HandlePlayerAuthCodeMsg);
- }
- public override void OnClientConnect(NetworkConnection conn)
- {
- ClientConn = conn;
- }
- //Server handles auth code response from player
- private void HandlePlayerAuthCodeMsg(NetworkMessage netMsg)
- {
- Debug.Log("HandlePlayerAuth");
- if (LogFilter.Debug) { Debug.Log("HandlePlayerAuthCodeMsg()"); }
- AuthCodeResponsMsg message = netMsg.ReadMessage<AuthCodeResponsMsg>();
- if (serverAuthentication.registeredUsers.Exists(u => u.uniqueId == message.UniqueID))
- {
- // GameObject test = Database.CharacterLoad("Test", GetPlayerClasses());
- // NetworkServer.AddPlayerForConnection(netMsg.conn, test);
- Debug.Log("Valid UniqueId, should instantiate player");
- //return;
- }
- else
- {
- // terminate connection.
- Debug.Log("UNIQUE WRONG Should DROP CONNECTION");
- }
- // string AccountName = Database.GetAccountFromUniqueID(message.UniqueID);
- // string CharacterName = Database.GetActiveCharacterFromAccount(AccountName);
- // Debug.Log("[Loading Character] - Account: " + AccountName + " Character: " + CharacterName);
- // GameObject go = Database.CharacterLoad(CharacterName, GetPlayerClasses());
- // NetworkServer.AddPlayerForConnection(netMsg.conn, go);
- // playerList.Add(new PlayerStruct() { connection = netMsg.conn, uniqueID = message.UniqueID, player = go.GetComponent<Player>() });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement