005. Foray into Photon - Part 04 Common

So last time we left off we can connect to the server, send it an operation and get a response back. Originally I said we were going to look at the OperationDispatcher but instead we a taking a small detour to begin getting set up for it. First we want to create a new class library project in the same solution as our server code. Just right-click on the AegisBorn solution and add a new project. I called mine AegisBornCommon. In this project we will create things that are common to the server and the client. Once the project is created, go to the server project and add a reference to the project AegisBornCommon.

Now that we have our common class library ready we are going to create several enumerations. These will help us determine what data we are trying to find or put into return values. I'm going to run through each of the files real quick. You will want to create 4 new items, use the class wizard and call them ErrorCode, EventCode, OperationCode, and ParameterCode. Here is the code for those 4 classes:

    public enum ErrorCode
    {
        ///<summary>
        /// The ok code.
        ///</summary>
        Ok = 0,

        ///<summary>
        /// The fatal.
        ///</summary>
        Fatal = 1,
    }

    public enum EventCode : byte
    {
    }

    public enum OperationCode : short
    {
        ///<summary>
        /// The nil (nothing).
        ///</summary>
        Nil = 0,
    }

    public enum ParameterCode : short
    {
        ///<summary>
        /// The error code.
        ///</summary>
        ErrorCode = 0,

        ///<summary>
        /// The debug message.
        ///</summary>
        DebugMessage = 1,
    }

If you notice, these are exactly the same as the ones in the MMO Demo. ErrorCodes are so we know if anything went wrong. EventCodes are so we can figure out which event was sent to us by the server, it also makes it easy for the server to know which event it is sending. OperationCode is for operations, much like events, it is so that we can know which operation the client wants to send to the server and so that the server can quickly figure out what it needs to do. Lastly the ParameterCode is for the OperationRequest and OperationResponse parameters/returnValues.

With these 4 files in place you will want to build this project and then copy the dll it puts into bin/Debug into your Plugins directory of your Unity3d project. Each time you build it you will need to copy it unless you know how to modify the project settings to tell it to put it in there directly.

Next time we will set up our system to use the OperationDispatcher. This saves our server from having the ugly switch statement that you would have to modify any time you add a new message and anything that keeps us from doing more work is a good thing.

Comments

i was having troubles with unity , it was because i built the Common project for NET FRAMEWORK 4
the solution to fix this was to make it :- .NET FRAMEWORK 3

You can use Post-Build event (it is in project properties->Build Events):
copy $(TargetPath) $(SolutionDir)..\..\..\..\Client\Assets\Plugins\

You can change destination folder to real one.

I am getting a Internal Compiler error in Unity3d, when I copy the AegisBornCommon.dll to unity3d Plugins.
I am running the Photon server in a Windows Machine and the Unity3d in different MAC OS. Thus, the configuration I do for the server is done with Visual C# and the Unity3d is configured with MonoDevelop. Am I doing something wrong here or haven't I followed the above tutorial procedure accurately?
The Part 04 is bit confusing for me. Is it asking us to add the AegisBornCommon project in to the existing solution and create 4 enum classes in it?

You will get an internal error when you try and run a .NET 4.0 dll through Unity3d. The first check you would want to make is that the AegisBornCommon project is being built with .NET 3.5. That should clear your error.

Yes you are adding the AegisBornCommon project to your existing solution and making those 4 enums in the common project.

Thanks a lot for your help