1

we are attempting to set up an online server and connect players to a server using Dark Rift, a collection of libraries. We are getting an error with a part of our code that checks when a player joins a game, it spawns a player connected to their ID:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DarkRift;
using DarkRift.Server;
using DarkRift.Client.Unity;

public class PlayerSpawner : MonoBehaviour
{
    const byte SPAWN_TAG = 0;

    [SerializeField]
    [Tooltip("The DarkRift client to communicate on.")]
    UnityClient client;

    [SerializeField]
    [Tooltip("The controllable player prefab.")]
    GameObject controllablePrefab;

    [SerializeField]
    [Tooltip("The network controllable player prefab.")]
    GameObject networkPrefab;

    void Awake()
    {
        if (client == null)
        {
            Debug.LogError("Client unassigned in PlayerSpawner.");
            Application.Quit();
        }

        if (controllablePrefab == null)
        {
            Debug.LogError("Controllable Prefab unassigned in PlayerSpawner.");
            Application.Quit();
        }

        if (networkPrefab == null)
        {
            Debug.LogError("Network Prefab unassigned in PlayerSpawner.");
            Application.Quit();
        }
        client.MessageReceived += SpawnPlayer;
    }
    void SpawnPlayer(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage())
        using (DarkRiftReader reader = message.GetReader())
        {
            if (message.Tag == Tags.SpawnPlayerTag)
            {
                if (reader.Length % 17 != 0)
                {
                    Debug.LogWarning("Received malformed spawn packet.");
                    return;
                }

                while (reader.Position < reader.Length)
                {
                    ushort id = reader.ReadUInt16();
                    Vector3 position = new Vector3(0, 0);

                    GameObject obj;
                    if (id == client.ID)
                    {
                        obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;
                    }
                    else
                    {
                        obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
                    }
                }
            }
        }
    }
}

In the client.MessageRecieved += SpawnPlayer; line it is not giving SpawnPlayer the argument of the type (it wants the MessageRecievedEventArgs, but is getting something else instead we think). The error says:

No overload for 'SpawnPlayer' matches delegate 'EventHandler<MessageReceivedEventArgs>'[Assembly-CSharp] csharp(cs0123) [43, 9]

Thank you very much!

Zach
  • 21
  • 1
  • 3
  • 1
    This probably could help [No overload matches delegate EventHandler](https://stackoverflow.com/questions/53924147/raise-event-c-sharp-gives-error-no-overload-matches-delegate-eventhandler) – Zak Dec 10 '19 at 16:18
  • Unfortunately it appears that their problem is that in their class definition they are missing an argument but mine has the required argument so I have a different issue. Thanks for the idea though! – Zach Dec 12 '19 at 14:45

1 Answers1

0

You want to use using Darkrift.client as well, and not darkrift.server in the heading. Cheers.

Oxygen
  • 1