//---------------------------------------------------------------------------------------------------------------- //--------------------------------------- SERVIDOR --------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------- public override void OnStartServer() { spawnPrefabs = Resources.LoadAll <GameObject>("SpawneablePrefabs").ToList(); managerClasification = gameObject.GetComponent <ClasificationManager>(); NetworkServer.RegisterHandler <TokenMessage>(OnServerTokenMessageHandler); string[] args = System.Environment.GetCommandLineArgs(); // El primer elemento es el nombre del ejecutable if (modoServidor == ServidorPartida) { NetworkServer.RegisterHandler <CombatResultMessage>(OnServerCombatResultMessageHandler); maxPlayers = maxConnections; for (int i = 0; i < maxPlayers; ++i) { tokens.Add(args[3 + i]); TokenDecoded aux = new TokenDecoded(args[3 + i], verify: false); users.Add(aux.userTag); managerClasification.AddNewPlayer(args[3 + i]); print("Cargado token " + args[3 + i] + " en server modo " + modoServidor); } } else { puertoOriginal = args[3]; maxPlayers = maxConnections; for (int i = 0; i < maxPlayers; ++i) { tokens.Add(args[4 + i]); TokenDecoded aux = new TokenDecoded(args[4 + i], verify: false); users.Add(aux.userTag); print("Cargado token " + args[4 + i] + " en server modo " + modoServidor); } } }
public TokenDecoded(string token, bool verify) { if (verify) { var json = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) // symmetric .WithSecret(GlobalVariables.TokenDecodeString) .MustVerifySignature() .Decode(token); TokenDecoded aux = JsonUtility.FromJson <TokenDecoded>(json); this.userTag = aux.userTag; this.iat = aux.iat; this.exp = aux.exp; } else { var json = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) // symmetric .WithSecret(GlobalVariables.TokenDecodeString) .Decode(token); TokenDecoded aux = JsonUtility.FromJson <TokenDecoded>(json); this.userTag = aux.userTag; this.iat = aux.iat; this.exp = aux.exp; } }
private void OnClientTablaClasificacionMessageHandler(TablaClasificacionMessage msg) { print("TablaClasificacion recibida"); if (UIActual.tag == UI_Prepartida) // Solo los que estén esperando (los otros estarán en UI_Fin) { ChangeUIActual(UI_Partida); } List <KeyValuePair <string, int[]> > clasificacion = new List <KeyValuePair <string, int[]> >(); for (int i = 0; i < msg.Tokens.Count; ++i) { TokenDecoded aux = new TokenDecoded(msg.Tokens[i], verify: false); clasificacion.Add(new KeyValuePair <string, int[]>(aux.userTag, msg.Resultados[i])); } clasificacionOrdenada = clasificacion; ActualizarTablaClasificacion(); }