-1

我正在使用 CRJ Gaming 教程创建基于光子的多人服务器我遇到了这个错误,尝试修复它超过 2 小时,重新观看教程几次,我完全迷失了。

错误:

Error   1   'FPS.Photon.Server.PhotonServerHandler' does not implement interface member 'FPS.Framework.IHandler<FPS.Photon.Server.PhotonServerPeer>.HandleMessage(FPS.Framework.IMessage, FPS.Photon.Server.PhotonServerPeer)'  C:\Users\Blagovest\documents\visual studio 2013\Projects\FPS\FPS.Photon\Server\PhotonServerHandler.cs   12  27  FPS.Photon

PhotonServerHandler

using ExitGames.Logging;
using FPS.Framework;
using FPS.Photon.Application;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPS.Photon.Server
{
    public abstract class PhotonServerHandler : IHandler<PhotonServerPeer>
    {
        public abstract MessageType Type { get; }
        public abstract byte Code { get; }
        public abstract int? SubCode { get; }
        protected PhotonApplication Server;
        protected ILogger Log = LogManager.GetCurrentClassLogger();

        public PhotonServerHandler(PhotonApplication application)
        {
            Server = application;
        }

        public bool HandleMessge(IMessage message, PhotonServerPeer serverPeer)
        {
            OnHandleMessage(message, serverPeer);
            return true;
        }

        protected abstract bool OnHandleMessage(IMessage message, PhotonServerPeer serverPeer);
    }
}

PhotonServerPeer

using FPS.Photon.Application;
using Photon.SocketServer;
using Photon.SocketServer.ServerToServer;
using PhotonHostRuntimeInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPS.Photon.Server
{
    public class PhotonServerPeer : ServerPeerBase
    {
        private readonly PhotonServerHandlerList _handlerList;
        protected readonly PhotonApplication Server;
        public Guid? ServerId { get; set; }
        public string TcpAddress { get; set; }
        public string UdpAddress { get; set; }
        public string ApplicationName { get; set; }
        public int ServerType { get; set; }

        #region Factory Method

        public delegate PhotonServerPeer Factory(IRpcProtocol protocol, IPhotonPeer photonPeer);

        #endregion

        public PhotonServerPeer(IRpcProtocol protocol, IPhotonPeer photonPeer, PhotonServerHandlerList handlerList, PhotonApplication application) : base(protocol, photonPeer)
        {
            _handlerList = handlerList;
            Server = application;
        }

        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            _handlerList.HandleMessage(new PhotonRequest(operationRequest.OperationCode, operationRequest.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationRequest.Parameters[Server.SubCodeParameterKey]) : null, operationRequest.Parameters), this);
        }

        protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
        {
            _handlerList.HandleMessage(new PhotonEvent(eventData.Code, eventData.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(eventData.Parameters[Server.SubCodeParameterKey]) : null, eventData.Parameters), this);
        }

        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            _handlerList.HandleMessage(new PhotonResponse(operationResponse.OperationCode, operationResponse.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationResponse.Parameters[Server.SubCodeParameterKey]) : null, operationResponse.Parameters, operationResponse.DebugMessage, operationResponse.ReturnCode), this);
        }

        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            Server.ConnectionCollection.OnDisconnect(this);
        }

    }
}
4

1 回答 1

0

错误消息为您提供了您需要知道的一切。

PhotonServerHandler 是一个实现接口 IHandler 的抽象类

这意味着在 IHandler 中声明的所有方法都必须在 PhotonServerHandler 中实现。

这是一个可靠的示例,说明了为什么会出现该错误

public interface A
{
    void DoThingOne();
    void DoThingTwo();
} 

public abstract class B : A
{
    DoThingOne()
}

上面会抛出一个错误。

如果您使用的是visual studio,请尝试右键单击界面,然后实现界面。

这应该从接口实现所有必要的方法。

于 2015-03-22T09:58:19.310 回答