Shadow Network Framework  0.0.2-alpha
.NET Client Library for Shadow Network Framework
Loading...
Searching...
No Matches
SNF's OPCodes

◄ Previous: Tutorials

before setting up OPCodes you must know what is an OPCode, See Request's OPCode for more details


Setting up new OPCodes

One thing to note is that you do not define whole OPCodes but you define each part of the OPCode one by one with a String definition of each Member, which means you define the Category, then the Sub-Category and so on

Warning
Never Add/Modify Base OPCode Members!
Note
Every OPCode Member that is of Command Rank, will have by default a Detail 0 called DET_UNDETAILED or could be called ' Undetailed Detail'

 Setting up a new Member

This is a General method for creating instances of a new member regardless of rank, however creating any member using this method requires you to add it manually to the OPCode structure, and/or it's parent if it should have one.

See Also

  1. For Categories See Creating and Adding the Category manually
  1. For SubCategories See Creating and Adding the SubCategory manually
  1. For Commands See Creating and Adding the Command manually
  1. For Details See Creating and Adding the Detail manually

This function requires you 3 Arguments:

  1. Member's Rank.
  2. Member's defining byte.
  3. Member's string definition (Optional, "" should be enough).

Example:

Creating a new category whose defining byte is 0x05 With a string definition of 'Simple Category'

using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
Member OurNewMember = new Member(
/// Rank Must be appropriate to where you
/// are going to insert it in
Member.Rank.Category,
/// The byte that represents this Category
0x05,
/// String Definition for this OPCode Command
/// *Not Mandatory, you can put "" fine
"Simple Category"
);
Objects of this class Define the action to do to the host.
Definition OPCode.cs:12
Definition Callbacks.cs:5

 Setting up a new Category

You can use the method stated in  Setting up a new Member and then add the Member instance you created and then add it to your opcode structure using AddCategory(Member), so unless you want to keep your Category's instance in a variable, then the use AddCategory(byte, string) would be better. See below for more details about both.

Creating and Adding the Category directly

To make it possible, we use the function AddCategory(byte, string) which requires you 2 arguments:

  1. Category's defining byte.
  2. Category's string definition (Optional, "" should be enough).
Note
Categories must start from 0x01 and up due to Category 0x00 is already defined as a Base Category

Example:

Creating a new category whose defining byte is 0x05 With a string definition of 'Simple Category'

using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
Member.AddCategory(
/// The byte that represents this Category
0x05,
/// String Definition for this OPCode Command
/// *Not Mandatory, you can put "" fine
"Simple Category"
);

Creating and Adding the Category manually

To make it possible, we create the member instance using the method stated in  Setting up a new Member ,then use the function AddCategory(Member) which requires you 1 arguments:

  1. Category's Member instance.
Note
Categories must start from 0x01 and up due to Category 0x00 is already defined as a Base Category

Example:

Creating a new category whose defining byte is 0x05 With a string definition of 'Simple Category'

using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
Member Category = new Member(
/// Rank Must be appropriate to where you
/// are going to insert it in
Member.Rank.Category,
/// The byte that represents this Category
0x05,
/// String Definition for this OPCode Command
/// *Not Mandatory, you can put "" fine
"Simple Category"
);
Member.AddCategory(
/// Category's Member Instance
Category
);

 Setting up a new SubCategory

You can use the method stated in  Setting up a new Member and then add the Member instance you created ( this time create the member instance with SubCategory Rank) and then add it to your opcode structure using AddSubCategory(Member, Member), so unless you want to keep your SubCategory's instance in a variable, then the use AddSubCategory(Member, byte, string) would be better. See below for more details about both.

Creating and Adding the SubCategory directly

To make it possible, we use the function AddSubCategory(Member, byte, string) which requires you 3 arguments:

  1. SubCategory's parent Category's instance.
  2. SubCategory's defining byte.
  3. SubCategory's string definition (Optional, "" should be enough).

Example:

Creating a new SubCategory whose defining byte is 0x00 With a string definition of 'Simple SubCategory' whose parent is the Category generated in the examples sated in  Setting up a new Category

Note
Assuming the parent category's instance is called Category
using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member.AddSubCategory(
/// The Parent Category's instance.
Category,
/// The byte that represents this SubCategory
0x00,
/// String Definition for this OPCode SubCategory
/// *Not Mandatory, you can put "" fine
"Simple SubCategory"
);

Creating and Adding the SubCategory manually

To make it possible, we create the member instance using the method stated in  Setting up a new Member with SubCategory Rank, then use the function AddSubCategory(Member, Member) which requires you 2 arguments:

  1. SubCategory's parent Category's instance.
  2. SubCategory's Member instance.

Example:

Creating a new SubCategory whose defining byte is 0x00 With a string definition of 'Simple SubCategory' whose parent is the Category generated in the examples sated in  Setting up a new Category

Note
Assuming the parent category's instance is called Category
using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member SubCategory = new Member(
/// Rank Must be appropriate to where you
/// are going to insert it in
Member.Rank.SubCategory,
/// The byte that represents this SubCategory
0x00,
/// String Definition for this OPCode SubCategory
/// *Not Mandatory, you can put "" fine
"Simple Command"
);
Member.AddSubCategory(
/// The Parent Category's instance.
Category,
/// SubCategory's Member Instance
SubCategory
);

 Setting up a new Command

Commands are different than the rest of OPCode Members because they (Even on the server side) define the functions to be called when they are triggered, If you create an Member instance you created with Command Rank, it will have no function to be called if the server sends a request with that command until you add it to your opcode structure.

Creating and Adding the Command directly

To make it possible, we use the function AddCommand(Member, byte, string, RequestCB) which requires you 4 arguments:

  1. Command's parent SubCategory's instance.
  2. Command's defining byte.
  3. Command's string definition (Optional, "" should be enough).
  4. Command's function that would be called if the server has raises this command.

Example:

Creating a new Command whose defining byte is 0x00 With a string definition of 'Simple Command' whose parent is the SubCategory generated in the examples sated in  Setting up a new SubCategory

Note
Assuming the parent category's instance is called SubCategory
using SNFClient;
/// Never Forget This
using static SNFClient.OPCode;
void OnServersRequestHandler(Request rqst)
{
....
}
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member.AddCommand(
/// The Parent SubCategory's instance.
SubCategory,
/// The byte that represents this Command
0x00,
/// String Definition for this OPCode Command
/// *Not Mandatory, you can put "" fine
"Simple Command",
/// The Server's handler
OnServersRequestHandler
);
"Request" Members are the object that are sent through SNF.Client.Connection
Definition Request.cs:19
Defines The Callbacks need for Event Handling.
Definition Callbacks.cs:10

Creating and Adding the Command manually

To make it possible, we create the member instance using the method stated in  Setting up a new Member ,then use the function AddCommand(Member, Member, RequestCB) which requires you 2 arguments:

  1. Command's parent Category's instance.
  2. Command's Member instance.
  3. Command's function that would be called if the server has raises this command.

Example:

Creating a new SubCategory whose defining byte is 0x00 With a string definition of 'Simple Command' whose parent is the SubCategory generated in the examples sated in  Setting up a new SubCategory

Note
Assuming the parent subcategory's instance is called SubCategory
using SNFClient;
/// Never Forget This
using static SNFClient.OPCode;
void OnServersRequestHandler(Request rqst)
{
....
}
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member Command = new Member(
/// Rank Must be appropriate to where you
/// are going to insert it in
Member.Rank.Command,
/// The byte that represents this SubCategory
0x05,
/// String Definition for this OPCode Command
/// *Not Mandatory, you can put "" fine
"Simple SubCategory"
);
Member.AddCommand(
/// The Parent SubCategory's instance.
SubCategory,
/// The byte that represents this Command
Command,
/// The Server's handler
OnServersRequestHandler
);

 Setting up a new Detail

You can use the method stated in  Setting up a new Member and then add the Member instance you created ( this time create the member instance with Detail Rank) and then add it to your opcode structure using AddDetail(Member, Member), so unless you want to keep your Detail's instance in a variable, then the use AddDetail(Member, byte, string) would be better. See below for more details about both.

Creating and Adding the Detail directly

To make it possible, we use the function AddDetail(Member, byte, string) which requires you 3 arguments:

  1. Detail's parent Command's instance.
  2. Detail's defining byte.
  3. Detail's string definition (Optional, "" should be enough).
Note
Details must start from 0x01 and up due to Detail 0x00 being already defined as an Undefined(or Undetailed) Detail

Example:

Creating a new Detail whose defining byte is 0x01 With a string definition of 'Simple Detail' whose parent is the Command generated in the examples sated in  Setting up a new Command

Note
Assuming the parent command's instance is called Command
using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member.AddDetail(
/// The Parent Command's instance.
Command,
/// The byte that represents this Detail
0x01,
/// String Definition for this OPCode Ddetail
/// *Not Mandatory, you can put "" fine
"Simple Detail"
);

Creating and Adding the Detail manually

To make it possible, we create the member instance using the method stated in  Setting up a new Member with Detail Rank, then use the function AddDetail(Member, Member) which requires you 2 arguments:

  1. Detail's parent Command's instance.
  2. Detail's Member instance.
Note
Details must start from 0x01 and up due to Detail 0x00 being already defined as an Undefined(or Undetailed) Detail

Example:

Creating a new Detail whose defining byte is 0x01 With a string definition of 'Simple Detail' whose parent is the Command generated in the examples sated in  Setting up a new Command

Note
Assuming the parent command's instance is called Command
using SNFClient;
using static SNFClient.OPCode;
..
/// Always Initialize OPCode.Base before anything
Base.Initialize();
..
Member Detail = new Member(
/// Rank Must be appropriate to where you
/// are going to insert it in
Member.Rank.Detail,
/// The byte that represents this Detail
0x00,
/// String Definition for this OPCode Detail
/// *Not Mandatory, you can put "" fine
"Simple Detail"
);
Member.AddDetail(
/// The Parent Command's instance.
Command,
/// SubCategory's Member Instance
Detail
);

Getting an OPCode Member

In case you want to fetch a Base OPCode Member for some reason, use one of the Following

Note
During all of these Examples below we use this using

using static SNFClient.OPCode;

Getting a Category

In case you want a specefic Category, you must use their defining byte

Member C = Member.getCategory(
/// Category's defining byte
0x00
);

or if you want the base Category

Member C = Base.getCategory();
Command
See also
OPCode.Member.getCategory(byte)
OPCode.Base.getCategory()

Getting a Subcategory

In case you want a specefic subcategory, you must use their defining byte and the parent Category's defining byte or the category Member instance.

/* Method 1*/
Member C = Member.getSubcategory(
/// Category's defining byte
0x00,
/// SubCategory's defining byte
0x00
);
/* Method 2*/
Member C = Member.getSubcategory(
/// Category's object instance
Category,
/// SubCategory's defining byte
0x00
);

or if you want the base SubCategory

Member C = Base.getSubCategory();
See also
OPCode.Member.getSubCategory(byte, byte)
OPCode.Member.getSubCategory(OPCode.Member, byte)
OPCode.Base.getSubcategory()

Getting a Command

In case you want a specefic command, you must use their defining byte and the parent Category and Subcategory's defining Byte or the Subcategory's Member Instance,

/* Method 1*/
Member C = Member.getCommand(
/// Category's defining byte
0x00,
/// SubCategory's defining byte
0x00,
/// The Command's defining byte
0x01
);
/* Method 2*/
Member C = Member.getCommand(
/// SubCategory's Member instance
Subategory,
0x00
);

or if you want a base command

Member C = Base.getCommand(
/// The Command's defining byte
0x01
);
See also
OPCode.Member.getCommand(byte, byte, byte)
OPCode.Member.getCommand(OPCode.Member, byte)
OPCode.Base.getCommand(byte)

Getting a Command's Detail

In case you want a specefic command's detail, you must use their defining byte and the parent Category, Subcategory and Command's defining byte or the Command's Member Instance,

/* Method 1*/
Member C = Member.getDetail(
/// Category's defining byte
0x00,
/// SubCategory's defining byte
0x00,
/// The Command's defining byte
0x01,
/// The Detail's defining byte
0x01,
);
/* Method 2*/
Member C = Member.getDetail(
/// Command's Member instance
Command,
/// The Detail's defining byte
0x00
);

or if you want a base command's detail

Member C = Base.getDetail(
/// The Command's defining byte
0x01,
/// The Detail's defining byte
0x01
);
See also
OPCode.Member.getDetail(byte, byte, byte, byte)
OPCode.Member.getDetail(OPCode.Member, byte)
OPCode.Base.getDetail(byte, byte)

Generating an OPCode

OPCodes are a Set of bytes who's sole purpose is defining the action to perform on the server side which are mandaroty to generate new Request Instances

Generating a Base OPCode

Note
You can Generate Base OPCodes using the same Method as Generating a User-defined OPCode but the The defining Byte for Base Category and Base Subcategory is 0x00

For Base OPCodes there is 2 Methods (Each having 2 Overloads)

1- Getting any base Command

/*Overload 1: In case you want to Include a detail */
/// Defining byte for the base command
/// Defining byte for the base Command
);
/*Overload 2: In case you want an undetailed OPCode */
/// Defining byte for the base command
);
This Class Defined THe Base OPCode Structure for Basic SNF Functioning.
Definition OPCode.cs:769
static OPCode get(byte Command)
Gets an OPCode using a Base Command without any detail.
static byte CMD_SNF_VER
When client requests SNF version of the Server.
Definition OPCode.cs:800
static byte DET_UNDETAILED
Default Detail for every Command.
Definition OPCode.cs:782

2- Getting the Invalid Command

/*Overload 1: In case you want to Include a detail */
/// A Defining byte for an Invalid Command Detail
)
/*Overload 2: In case you want an undetailed 'Invalid' OPCode */
static byte DET_INVALID_ERROR_PROTOCOL
Protocol used is invalid.
Definition OPCode.cs:826
static OPCode getInvalid()
Gets an OPCode using a 'Invalid' Command without any detail.

Generating a User-defined OPCode

There is 2 Methods To Generate an OPCode

1- Using The defining byte of it's Members

...
/// Never Forget to Initialize the Base OPCodes
/// once before doing anything
OPCode.Base.Initialize();
...
OPCode opcode = OPCode.get(
/// Defining Byte for the Category
0x01,
/// Defining Byte for the Subcategory
0x00,
/// Defining Byte for the Command
0x02,
/// Defining Byte for the Command's Detail
/// OPTIONAL
0x05
);
static OPCode get(byte Category, byte SubCategory, byte Command, byte Detail=0)
Generates an OPCode Instnce Depending on the Registred Parameters.
Definition OPCode.cs:57

2- Using OPCode.Member Instances of it's Members

See Also:

...
/// Never Forget to Initialized the Base OPCodes
/// once before doing anything
OPCode.Base.Initialize();
...
OPCode.Member Category;
OPCode.Member SubCategory;
OPCode.Member Command;
...
OPCode opcode = OPCode.get(
/// OPCode.Member instance of the Category
Category,
/// Defining Byte for the Subcategory
SubCategory,
/// Defining Byte for the Command
Command,
/// Defining Byte for the Command's Detail
/// OPTIONAL
Detail
);
Objects of this class Defines every OPCode instance.
Definition OPCode.cs:194
Note
If you want Undetailed OPCodes using Method 1 and/or 2 you can put in the OPTIONAL Parameter with a value of 0x00 and/or null respectively, or not write that parameter to begin with

Next: SNF's Connection(s) ►