예제 #1
0
    public void JoinServer(string ipAddress, string matchmakerTicket)
    {
        if (!client.Connected)
        {
            if (forceLocalhost)
            {
                ipAddress = "127.0.0.1";
            }

            try {
                Debug.Log("DarkRift: Requesting to join server at IP address: " + ipAddress);
                ServerJoinUpdate?.Invoke("DarkRift: Requesting to join server at IP address: " + ipAddress);
                client.Connect(System.Net.IPAddress.Parse(ipAddress), client.Port, client.IPVersion);
            } catch (System.Exception e) {
                Debug.LogError("DarkRift: Connection failed to server at IP address: " + ipAddress + "\nError: " + e);
                ServerJoinFailure?.Invoke("DarkRift: Connection failed to server at IP address: " + ipAddress);
            }
        }

        if (client.Connected)
        {
            Debug.Log("DarkRift: Writing matchmaker ticket to server...");
            ServerJoinUpdate?.Invoke("DarkRift: Writing matchmaker ticket to server...");
            using (DarkRiftWriter writer = DarkRiftWriter.Create()) {
                writer.Write(matchmakerTicket);

                using (Message message = Message.Create(NetworkTags.Connection, writer)) {
                    client.SendMessage(message, SendMode.Reliable);
                }
            }
        }
        else
        {
            Debug.LogError("DarkRift: Connection failed to server at IP address: " + ipAddress);
            ServerJoinFailure?.Invoke("DarkRift: Connection failed to server at IP address: " + ipAddress);
        }
    }
예제 #2
0
 public void OnJoinServerUpdate(string message)
 {
     Debug.Log(message);
     ServerJoinUpdate?.Invoke(message);
 }