public NetworkConnectionError StartServer(bool addToServerList) { NetworkConnectionError error; Network.InitializeSecurity(); error = Network.InitializeServer(settings.maxPlayers - 1, settings.port, !Network.HavePublicAddress()); //Get player type PlayerType myType = PlayerType.Anon; if (GameSettings.user.token != "") { myType = PlayerTypeHandler.GetPlayerType(GameSettings.user.playerName); } networkView.RPC("AddPlayerToList", RPCMode.All, Network.player, GameSettings.user.playerName, (int)myType); networkView.RPC("SetHost", RPCMode.AllBuffered, Network.player); //Set host for all players joining if (addToServerList) { isOnServerList = true; RegisterServer("In lobby"); } SendPublicMsg("Welcome to Sanicball!"); return(error); }
void SetupPlayer(NetworkPlayer player, string name, bool isAnon) { if (!Network.isServer) { return; } //Check if this player's version has been accepted if (connectionTimeout.ContainsKey(player)) { //This only happens when an older version joins a newer version. Therefore, Kick cannot be used. Slightly obsolete code. Network.CloseConnection(player, true); SendServerMsg("Player joined with wrong version and was kicked."); connectionTimeout.Remove(player); } //Set stuff on the newly connected player networkView.RPC("ChangeLevel", player, Application.loadedLevel); SendPublicMsg(name + " has joined the game."); //Add other players to new player's player list and do stuff with the new players foreach (ServerPlayer sp in client.GetPlayerList()) { networkView.RPC("AddPlayerToList", player, sp.player, sp.name, (int)sp.type); networkView.RPC("SetReady", player, sp.player, sp.ready); networkView.RPC("SetCharacter", player, sp.player, sp.character); networkView.RPC("SetSpectating", player, sp.player, sp.spectating); } //Grab new player's type PlayerType pType = PlayerType.Anon; if (!isAnon) { pType = PlayerTypeHandler.GetPlayerType(name); } //Add new player to everyone's player list networkView.RPC("AddPlayerToList", RPCMode.All, player, name, (int)pType); if (!client.IsInLobby) //Means the game is in progress. //networkView.RPC("SetSpectating",RPCMode.All,player,true); { SendPrivateMsg("You'll be able to race once the next round starts.", player); RaceController rc = GameObject.FindObjectOfType <RaceController>(); networkView.RPC("JoinRaceInProgress", player, rc.settings.ToString()); } else //Means we're in the lobby. { networkView.RPC("SetInitLobbyOnLevelLoad", player); //Sets the new player's character, forcing all players to spawn him into the lobby networkView.RPC("SetCharacter", RPCMode.All, player, 0); } Debug.Log("Player " + name + " has been successfully set up on clients."); }
public void DrawGUI() { GUIStyle smallButton = GUI.skin.GetStyle("smallButton"); if (page == 0) { if (GUILayout.Button("General")) { page = 1; } if (GUILayout.Button("Keybinds")) { page = 2; } if (GUILayout.Button("Profile")) { page = 3; } if (GUILayout.Button("Back", smallButton)) { menu.SetPage(MenuPage.None); } } if (page == 1) //General settings { enableTrails = GUILayout.Toggle(enableTrails, "Fancy ball trails"); fullscreen = GUILayout.Toggle(fullscreen, "Fullscreen"); vsync = GUILayout.Toggle(vsync, "Vsync"); Resolution currentRes = Screen.resolutions[(int)resolution]; GUILayout.Label("Resolution: " + currentRes.width + "x" + currentRes.height); resolution = GUILayout.HorizontalSlider(resolution, 0, Screen.resolutions.Length - 1); //GUILayout.Label ("Field of View: "+fov); //fov = (int)GUILayout.HorizontalSlider(fov,50,80); //AA buttons GUILayout.Label("Anti-aliasing: x" + aa); GUILayout.BeginHorizontal(); if (GUILayout.Button("Off", smallButton)) { aa = 0; } if (GUILayout.Button("x2", smallButton)) { aa = 2; } if (GUILayout.Button("x4", smallButton)) { aa = 4; } if (GUILayout.Button("x8", smallButton)) { aa = 8; } GUILayout.EndHorizontal(); //Dynamic shadows shadows = GUILayout.Toggle(shadows, "Dynamic Shedews"); //Camera speed for mouse / keyboard seperately GUILayout.Label("Camera speed (Mouse): " + (float)decimal.Round((decimal)sensitivityMouse, 1)); sensitivityMouse = GUILayout.HorizontalSlider(sensitivityMouse, 0.1f, 10); GUILayout.Label("Camera speed (Keyboard): " + (float)decimal.Round((decimal)sensitivityKeyboard, 1)); sensitivityKeyboard = GUILayout.HorizontalSlider(sensitivityKeyboard, 0.1f, 30); //sound volume GUILayout.Label("Sound volume: " + (float)decimal.Round((decimal)volume, 2) * 100 + "%"); volume = GUILayout.HorizontalSlider(volume, 0, 1); //Music toggle music = GUILayout.Toggle(music, "Music"); //sanic speed song sanicSpeedSong = GUILayout.Toggle(sanicSpeedSong, "Alt. song when going fast"); if (GUILayout.Button("Apply")) { Apply(); } if (GUILayout.Button("Back", smallButton)) { page = 0; UpdateVarsGeneral(); } } if (page == 2) //Keybind changer { foreach (KeyValuePair <string, KeybindInfo> bind in GameSettings.keybinds.GetAllBinds()) { GUILayout.BeginHorizontal(); GUILayout.Label(bind.Value.name, GUILayout.MaxWidth(200)); GUILayout.FlexibleSpace(); GUIStyle keycodeStyle = new GUIStyle(smallButton); keycodeStyle.alignment = TextAnchor.MiddleRight; if (GUILayout.Button(GameSettings.keybinds.GetKeyCodeName(bind.Value.keyCode), keycodeStyle, GUILayout.MaxWidth(200))) { keybindToChange = bind.Key; } GUILayout.EndHorizontal(); } if (GUILayout.Button("Reset keybinds", smallButton)) { GameSettings.keybinds = new Keybinds(); } if (string.IsNullOrEmpty(keybindToChange)) { if (GUILayout.Button("Apply")) { Apply(); } if (GUILayout.Button("Back", smallButton)) { page = 0; GameSettings.keybinds.LoadFromPrefs(); } } else { KeybindInfo info = GameSettings.keybinds.Find(keybindToChange); GUILayout.Label("Press a key to use for '" + info.name + "'. Escape to cancel."); } } if (page == 3) //Profile { if (GameSettings.user.UseGJ) //Logged in menu { GUILayout.Label("Signed in to Game Jolt as " + GameSettings.user.playerName); GUILayout.Label("'Remember me' is " + (GameSettings.user.rememberInfo ? "ON" : "OFF")); GUILayout.Label("Player status: " + PlayerTypeHandler.GetPlayerType(GameSettings.user.playerName)); if (GUILayout.Button("Log out")) { loginToken = GameSettings.user.token; loginName = GameSettings.user.playerName; GameSettings.user.token = ""; GameSettings.user.Save(); } } else //Anon menu { GUILayout.Label("Playing anonymously as '" + GameSettings.user.playerName + "'"); GUILayout.Label("'Remember me' is " + (GameSettings.user.rememberInfo ? "ON" : "OFF")); GUILayout.Label("Change your username:"******"Change", smallButton)) { GameSettings.user.playerName = anonName; } if (!GameSettings.user.offlineMode) { if (GUILayout.Button("Log in with Game Jolt", GUI.skin.GetStyle("smallbuttongreen"))) { page = 4; } } } if (GUILayout.Button("Back", smallButton)) { page = 0; UpdateVarsProfile(); } } if (page == 4) //Log in { GUILayout.Label("GJ username: "******"Focus"); loginName = GUILayout.TextField(loginName, 128); GUILayout.Label("User token: "); loginToken = GUILayout.PasswordField(loginToken, (char)0x25CF, 128); rememberMe = GUILayout.Toggle(rememberMe, "Remember me"); if ((GUILayout.Button("Log in") || (Event.current.isKey && Event.current.keyCode == KeyCode.Return)) && !isVerifying) { status = ""; if (loginName.Trim().Length <= 0) //Has the user typed something in the username field? { status = "You need to type an username."; } else if (loginToken.Trim().Length <= 0) //Has the user typed something in the token field? { status = "You need to type in your token."; } else //Log in with the Game Jolt API { status = "@spinner/Logging in..."; isVerifying = true; GJAPI.Users.Verify(loginName, loginToken); GJAPI.Users.VerifyCallback += LogInCallback; } } if (status.StartsWith("@spinner/")) { Spinner.Draw(status.Replace("@spinner/", "")); } else { GUILayout.Label(status); } if (GUILayout.Button("Back", smallButton) && !isVerifying) { page = 3; } } }