public void AttemptConnect(string ip, ushort port, string password, bool reset = true) { IsConnecting = true; Provider = new LidgrenClient(this); ClientID = ((ClientMultiplayerProvider)Provider).GetUserID(); ClientName = ((ClientMultiplayerProvider)Provider).GetClientName(); CurrentTime = Provider.GetServerRealTime(); LogUtils.Log("Attempting conncetion to " + ip + ":" + port + " (using password: "******"NO" : "YES") + ")"); if (IsConnected) { LogUtils.Debug("Already connnected to a server"); return; } if (reset) { _serverQueryAttempts = 0; } _currentIp = ip; _currentPort = port; CurrentPassword = password; ((ClientMultiplayerProvider)Provider).AttemptConnect(ip, port, password); }
public void Init() { Provider = new LidgrenClient(this); IsSinglePlayer = true; _server.OpenGameServer(true); _server.SinglePlayerConnection = this; ClientName = "Player"; ClientID = new IPIdentity(0); ServerID = ClientID; ConnectToServer(); }
private void OnGUI() { float num = (float)Screen.width / 2f; float num2 = (float)Screen.height / 2f; if (GUI.Button(new Rect(num - 50f, num2 - 12f, 100f, 20f), "Start Server")) { LidgrenServer lidgrenServer = (LidgrenServer)UnityEngine.Object.FindObjectOfType(typeof(LidgrenServer)); lidgrenServer.enabled = true; Application.LoadLevel("Level"); } if (GUI.Button(new Rect(num - 50f, num2 + 12f, 100f, 20f), "Start Client")) { LidgrenClient lidgrenClient = (LidgrenClient)UnityEngine.Object.FindObjectOfType(typeof(LidgrenClient)); lidgrenClient.enabled = true; Application.LoadLevel("Level"); } }
void OnGUI() { float halfWidth = Screen.width / 2f; float halfHeight = Screen.height / 2f; if (GUI.Button(new Rect(halfWidth - 50, halfHeight - 12, 100, 20), "Start Server")) { LidgrenServer server = (LidgrenServer)FindObjectOfType(typeof(LidgrenServer)); server.enabled = true; Application.LoadLevel("Level"); } if (GUI.Button(new Rect(halfWidth - 50, halfHeight + 12, 100, 20), "Start Client")) { LidgrenClient client = (LidgrenClient)FindObjectOfType(typeof(LidgrenClient)); client.enabled = true; Application.LoadLevel("Level"); } }
// Use this for initialization void Awake() { m_Client = new LidgrenClient(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { this.IsMouseVisible = true; response = ""; // Initialize the GoblinXNA framework State.InitGoblin(graphics, Content, ""); // Initialize the scene graph scene = new Scene(this); State.EnableNetworking = true; State.IsServer = false; // Set up the lights used in the scene CreateLights(); // Set up the camera, which defines the eye location and viewing frustum CreateCamera(); // Create 3D objects CreateObject(); // Use per pixel lighting for better quality (If you using non NVidia graphics card, // setting this to true may reduce the performance significantly) scene.PreferPerPixelLighting = true; // Create a network object that contains mouse press information to be // transmitted over network networkObj = new MessageNetworkObject(); // When a mouse press event is sent from the other side, then call "ShootBox" // function networkObj.CallbackFunc = UpdateMessage; // Create a network handler for handling the network transfers NetworkHandler networkHandler = new NetworkHandler(); if (3 == 4) { networkHandler.NetworkServer = new LidgrenServer("InfoOverload", 14242); } else { // Create a client that connects to the local machine assuming that both // the server and client will be running on the same machine. In order to // connect to a remote machine, you need to either pass the host name or // the IP address of the remote machine in the 3rd parameter. client = new LidgrenClient("InfoOverload", 14242, "Localhost"); // If the server is not running when client is started, then wait for the // server to start up. client.WaitForServer = true; networkHandler.NetworkClient = client; } scene.BackgroundColor = Color.Black; // Assign the network handler used for this scene scene.NetworkHandler = networkHandler; // Add the mouse network object to the scene graph, so it'll be sent over network // whenever ReadyToSend is set to true. scene.NetworkHandler.AddNetworkObject(networkObj); //scene.PhysicsEngine = new NewtonPhysics(); //Set to false for window graphics.IsFullScreen = fullScreen; graphics.ApplyChanges(); // Add a keyboard press handler for user input KeyboardInput.Instance.KeyPressEvent += new HandleKeyPress(KeyPressHandler); State.ShowNotifications = false; base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); #if WINDOWS this.IsMouseVisible = true; #endif // Initialize the GoblinXNA framework State.InitGoblin(graphics, Content, ""); // Initialize the scene graph scene = new Scene(); State.EnableNetworking = true; State.IsServer = isServer; State.ShowNotifications = true; State.ShowFPS = true; Notifier.FadeOutTime = 2000; // Set up the lights used in the scene CreateLights(); // Set up the camera, which defines the eye location and viewing frustum CreateCamera(); // Create 3D objects CreateObject(); // Create a network object that contains mouse press information to be // transmitted over network mouseNetworkObj = new MouseNetworkObject(); // When a mouse press event is sent from the other side, then call "ShootBox" // function mouseNetworkObj.CallbackFunc = ShootBox; // Create a network handler for handling the network transfers INetworkHandler networkHandler = null; #if USE_SOCKET_NETWORK || WINDOWS_PHONE networkHandler = new SocketNetworkHandler(); #else networkHandler = new NetworkHandler(); #endif if (State.IsServer) { IServer server = null; #if WINDOWS #if USE_SOCKET_NETWORK server = new SocketServer(14242); #else server = new LidgrenServer("Tutorial10", 14242); #endif State.NumberOfClientsToWait = 1; scene.PhysicsEngine = new NewtonPhysics(); #else scene.PhysicsEngine = new MataliPhysics(); ((MataliPhysics)scene.PhysicsEngine).SimulationTimeStep = 1 / 30f; #endif scene.PhysicsEngine.Gravity = 30; server.ClientConnected += new HandleClientConnection(ClientConnected); server.ClientDisconnected += new HandleClientDisconnection(ClientDisconnected); networkHandler.NetworkServer = server; } else { IClient client = null; // Create a client that connects to the local machine assuming that both // the server and client will be running on the same machine. In order to // connect to a remote machine, you need to either pass the host name or // the IP address of the remote machine in the 3rd parameter. #if WINDOWS client = new LidgrenClient("Tutorial10", 14242, "Localhost"); #else client = new SocketClient("10.0.0.2", 14242); #endif // If the server is not running when client is started, then wait for the // server to start up. client.WaitForServer = true; client.ConnectionTrialTimeOut = 60 * 1000; // 1 minute timeout client.ServerConnected += new HandleServerConnection(ServerConnected); client.ServerDisconnected += new HandleServerDisconnection(ServerDisconnected); networkHandler.NetworkClient = client; } // Assign the network handler used for this scene scene.NetworkHandler = networkHandler; // Add the mouse network object to the scene graph, so it'll be sent over network // whenever ReadyToSend is set to true. scene.NetworkHandler.AddNetworkObject(mouseNetworkObj); MouseInput.Instance.MousePressEvent += new HandleMousePress(MouseInput_MousePressEvent); }