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
{
///
/// The ok code.
///
Ok = 0,
///
/// The fatal.
///
Fatal = 1,
}
public enum EventCode : byte
{
}
public enum OperationCode : short
{
///
/// The nil (nothing).
///
Nil = 0,
}
public enum ParameterCode : short
{
///
/// The error code.
///
ErrorCode = 0,
///
/// The debug message.
///
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.
2 comments:
Hey :)
there is a small typo in the codes it's 2 time ErrorCode - think one of it should be EventCode.
Cheers
-Seb
Fixed it, thanks! I must have skipped hitting the copy button.
Post a Comment