Enertime
  • 🐣Enertime
  • Overview
    • 💡What we do
    • ✨Our Features
  • Fundamentals
    • 🛠️Installing Enertime
    • 🤾Using Enertime
      • 📝Usage Basics
      • 🧑Playing a Game!
  • Use Cases
    • 🖥️For Developers
      • 🤖Simple Integration
      • 👾Advanced Integration
        • Custom Protocol Sheet
  • Afterward
    • 🌱Future Development
Powered by GitBook
On this page
  1. Use Cases
  2. For Developers

Advanced Integration

For ADVANCED INTEGRATION features, please make a formal request to ENERTIME using the following email address: info@enertime.io

Upon requesting for Advanced Integration, you will receive the following files from Enertime.

  1. BeginOrEnd.cs

  2. CmdTypes.cs

  3. SerInstance.cs

  4. Utils.cs

Among these files, the main file that you will be working with is SerInstance.cs The other files are part of its dependencies, but its code need not be modified.

DEVELOPER NOTE: "The export format must be in Windows/MAC/Linux"


Now, please follow the below steps to integrate our solution with your product.

Step 1: Adding files into your game repository

  • Add the above 4 files that you will receive from us at Enertime, into a new folder within your working project file.

Step 2: Create a new script to extend the original SerInstance Class

  • Extend your class accordingly, using the sample provided below:

// Sample Code - C#
public class YourClass : EWTSerLib.SerInstance
{
    public static void IntilizeFunction()
    {
        YourClass yourClass = new YourClass();
    }

    YourClass()
    {
        base.Begin();
    }
}

Step 3: Begin the Override process with the SetAddresses() method

  • DESCRIPTION: void SetAddresses(int[][] IPA){}

    • Contains a 2D array of integers

    • In a single dimension, 1D, it represents an IP address.

    • Its main use is to generate the QR code used to establish a connection between the client and the server (executed every 5 seconds for stable connection).

    • Format of data (add an example):

      • When only 1 IP Address :

        • Eg: “ENERTIME: 192.168.1.1]”

      • When more than 1:

        • Eg: “ENERTIME: 192.168.1.1|192.168.1.213|......192.168.1.254]”

    • In addition, there is a padding feature, where every byte must have a length of 3, else it will append 0s to it’s left.

      The sample code for the override may be found below:

// Sample Override method for void SetAddresses(int[][] IPA){}
public override void SetAddresses(int[][] input)
    {
        string result = "ENERTIME: "; 
        int len = input.Length;

        for(int i = 0; i < len; i++)
        {
            result = result + String.Format("{0:000}{1:000}{2:000}{3:000}", input[i][0], input[i][1], input[i][2], input[i][3]);
            result = result + "|"; 
        }

        char[] resultArr = result.ToCharArray();
        resultArr[resultArr.Length - 1] = ']';
        result = new string(resultArr);
}

The result variable is used to make the QR code for connection purposes. The format is as follows:

result = “ENERTIME: 192.168.1.1|192.168.1.213|......192.168.1.254]”

Step 4: Begin the Override for the SetMode method

  • Description: void SetMode(byte clientID, byte mode){}

    • Stores information about the client’s playing mode.

    For the successful override of this function, please follow these procedures

    1. Create a byte array as a member of the newly created extended class

    2. Set minimum size to 8, but max limit is upto your choosing.

    3. Set the default value for every element of this array to 254.

    4. Store the modes as an array within the parameter clientID as follows: array[clientID] = mode

Here, 254 is used as a placeholder within the array. It is also used as an indicator for the connection status of the users (as 254 implies that the user is disconnected from the server).

The latter is mainly used for the below function.

Step 5: Override for the Disconnected() method

  • DESCRIPTION: public override void Disconnected(byte clientID){}

    • Used to detect if the player (phone/client) is connected to the server.

    • Cases where the client is disconnected from the server:

      1. Internet connection resets during gameplay. (maybe wifi network changed, or connected hotspot turned off)

      2. Client finishes playing the game

  • Steps:

    • If this instruction is passed, please execute the following code segment: array[clientID] = 254

Step 6: Override the HandleCommand() method

  • DEFINE: public override void HandleCommand(byte clientID,CmdType type, byte[] paras){}

  • DESCRIPTION:

    • Please refer to the sample code for the function below:

// HandleCommand(
public override void HandleCommand(byte clientID,CmdType type, byte[] paras)
    {
        //saber 
        if ((type == CmdType.SLASH) &&(paras[0] == 1)) // right 
        {
            rightTrigger = true;
        }
        else if ((type == CmdType.SLASH) &&(paras[1] == 1)) // left 
        {
            leftTrigger = true;
        }
        // Jump
        if ((type == CmdType.JUMP) && (paras[1] == 0) && (paras[0] > 0) )
        {
            Trigger = true;
        }
        // punch mode  CmdType.PUNCH
        if ((type == CmdType.PUNCH) && (paras[1] == 0) && (paras[0] > 0) )
        {
            Trigger = true;
        }
    }

Apart from Saber mode and Jump mode, if you would like to try some of the other modes, please utilize the protocol codes within the instruction sheet in the next section.

A quick summary of the code used is provided below.

Overridable Function: A function that is re-used/inherited from a pre-existing class, but is modified to perform different tasks during execution

void SetAddresses(int[][] IPA){}
void SetMode(byte clientID, byte mode){}
public override void Disconnected(byte clientID){}
public override void HandleCommand(byte clientID,CmdType type, byte[] paras){}
// Sample New Script to extend SerInstance.cs
public class YourClass : EWTSerLib.SerInstance
{
    public static void IntilizeFunction()
    {
        YourClass yourClass = new YourClass();
    }

    YourClass()
    {
        base.Begin();
    }
}
// Sample Override method for void SetAddresses(int[][] IPA){}
public override void SetAddresses(int[][] input)
    {
        string result = "ENERTIME: "; 
        int len = input.Length;

        for(int i = 0; i < len; i++)
        {
            result = result + String.Format("{0:000}{1:000}{2:000}{3:000}", input[i][0], input[i][1], input[i][2], input[i][3]);
            result = result + "|"; 
        }

        char[] resultArr = result.ToCharArray();
        resultArr[resultArr.Length - 1] = ']';
        result = new string(resultArr);
}
 // The format of the function definition is as follows
 void SetMode(byte clientID, byte mode){}
 
 // Stores information about the client’s playing mode
 // Refer to the document above for more information 
// The format of the function definition is as follows
public override void Disconnected(byte clientID){}

// Used to detect if the player (phone/client) is connected to the server
// Refer to the section above for more details
// The format of the function definition is as follows
// HandleCommand(
public override void HandleCommand(byte clientID,CmdType type, byte[] paras)
    {
        //saber 
        if ((type == CmdType.SLASH) &&(paras[0] == 1)) // right 
        {
            rightTrigger = true;
        }
        else if ((type == CmdType.SLASH) &&(paras[1] == 1)) // left 
        {
            leftTrigger = true;
        }
        // Jump
        if ((type == CmdType.JUMP) && (paras[1] == 0) && (paras[0] > 0) )
        {
            Trigger = true;
        }
        // punch mode  CmdType.PUNCH
        if ((type == CmdType.PUNCH) && (paras[1] == 0) && (paras[0] > 0) )
        {
            Trigger = true;
        }
    }

By making use of these functions, you can have your ideas make effective use of our solution.

PreviousSimple IntegrationNextCustom Protocol Sheet

Last updated 1 year ago

🖥️
👾