Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.64 KB | None | 0 0
  1. using UnityEngine;
  2. using Mirror;
  3. using Insight;
  4.  
  5. public class CNetworkManager : NetworkManager
  6. {
  7.  
  8.     private NetworkClient networkClient;
  9.     public string UniqueID;
  10.  
  11.     private ServerAuthentication serverAuthentication;
  12.     private ClientAuthentication clientAuthentication;
  13.  
  14.     private GameObject insightServer;
  15.     private GameObject insightClient;
  16.  
  17.     private NetworkConnection ClientConn;
  18.     private NetworkConnection ServerConn;
  19.  
  20.     public override void Awake()
  21.     {
  22.         base.Awake();
  23.         insightServer = GameObject.FindWithTag("InsightClient");
  24.         insightClient = GameObject.FindWithTag("InsightServer");
  25.  
  26.         serverAuthentication = insightServer.GetComponentInChildren<ServerAuthentication>();
  27.         clientAuthentication = insightClient.GetComponentInChildren<ClientAuthentication>();
  28.  
  29.     }
  30.  
  31.  
  32.  
  33.     public override void OnStartClient(NetworkClient client)
  34.     {
  35.         if (LogFilter.Debug) { Debug.Log("OnStartClient()"); }
  36.  
  37.         base.OnStartClient(client);
  38.  
  39.         networkClient = client;
  40.  
  41.         RegisterClientHandlers();
  42.     }
  43.  
  44.     void RegisterClientHandlers()
  45.     {
  46.         ClientConn.RegisterHandler((short)MsgId.AuthCodeRequestMsg, HandleAuthCodeRequest);
  47.     }
  48.  
  49.     public void HandleAuthCodeRequest(NetworkMessage netMsg)
  50.     {
  51.         AuthCodeRequestMsg msg = netMsg.ReadMessage<AuthCodeRequestMsg>();
  52.  
  53.         ClientConn.Send((short)MsgId.AuthCodeResponsMsg, new AuthCodeResponsMsg() { UniqueID = UniqueID });
  54.     }
  55.  
  56.     //Player Connects to Server
  57.     public override void OnServerConnect(NetworkConnection conn)
  58.     {
  59.         ServerConn = conn;
  60.  
  61.         if (LogFilter.Debug) { Debug.Log("OnServerConnect()"); }
  62.         base.OnServerConnect(conn); //Tells the client to connect to the correct scene
  63.  
  64.         //Request AuthCode
  65.         if (LogFilter.Debug) { print("Requesting AuthCode"); }
  66.         ServerConn.Send((short)MsgId.AuthCodeRequestMsg, new AuthCodeRequestMsg());
  67.  
  68.         RegisterServerHandlers();
  69.  
  70.     }
  71.  
  72.     void RegisterServerHandlers()
  73.     {
  74.         NetworkServer.RegisterHandler((short)MsgId.AuthCodeResponsMsg, HandlePlayerAuthCodeMsg);
  75.     }
  76.  
  77.     public override void OnClientConnect(NetworkConnection conn)
  78.     {
  79.         ClientConn = conn;
  80.     }
  81.  
  82.     //Server handles auth code response from player
  83.     private void HandlePlayerAuthCodeMsg(NetworkMessage netMsg)
  84.     {
  85.  
  86.         Debug.Log("HandlePlayerAuth");
  87.         if (LogFilter.Debug) { Debug.Log("HandlePlayerAuthCodeMsg()"); }
  88.  
  89.         AuthCodeResponsMsg message = netMsg.ReadMessage<AuthCodeResponsMsg>();
  90.  
  91.         if (serverAuthentication.registeredUsers.Exists(u => u.uniqueId == message.UniqueID))
  92.         {
  93.             // GameObject test = Database.CharacterLoad("Test", GetPlayerClasses());
  94.             // NetworkServer.AddPlayerForConnection(netMsg.conn, test);
  95.  
  96.             Debug.Log("Valid UniqueId, should instantiate player");
  97.             //return;
  98.         }
  99.         else
  100.         {
  101.             // terminate connection.
  102.             Debug.Log("UNIQUE WRONG Should DROP CONNECTION");
  103.         }
  104.  
  105.        // string AccountName = Database.GetAccountFromUniqueID(message.UniqueID);
  106.        // string CharacterName = Database.GetActiveCharacterFromAccount(AccountName);
  107.  
  108.       //  Debug.Log("[Loading Character] - Account: " + AccountName + " Character: " + CharacterName);
  109.  
  110.         // GameObject go = Database.CharacterLoad(CharacterName, GetPlayerClasses());
  111.       //  NetworkServer.AddPlayerForConnection(netMsg.conn, go);
  112.  
  113.        // playerList.Add(new PlayerStruct() { connection = netMsg.conn, uniqueID = message.UniqueID, player = go.GetComponent<Player>() });
  114.     }
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement