Adding server messages

From VbGORE Visual Basic Online RPG Engine

Server messages are referred to by their ID and the message itself is stored on the client. This allows for less bandwidth usage, along with more message processing (such as multiple language support). Although you do not have to do this with messages, it is recommended that you do for as many as you can.

Contents

[edit] Message file

The first step is to go into the \Data\Messages\ folder and add your message to the language file (such as english.ini). The number on the left is the message ID while the text on the right is the message itself. The message ID must be unique from every other ID in the list. Messages support variables, which are often denoted by <> tags, but these are not automatic - you must do extra work to support them. For example:

135=You lost <amount> <objname>(s).

<amount> and <objname> are replaced when the client reads the message from the server, and the server must pass additional values.

After you add your messages, update _nummessages.ini with the highest message ID.

[edit] On the server

There are two ways messages are sent - either through a pre-cached byte array or by building the message packet. Pre-cached messages can only be done for messages with no extra parameters, but are faster and easier to write.

[edit] Pre-cached

To add a message to the pre-cached message list, search the code for:

Const cMessages As String =

Anywhere in this huge string list, add the ID of your message. The code will take care of the rest for you. You can now make a reference to that message by using:

cMessage(ID).Data()

For example, this:

Data_Send ToIndex, UserIndex, cMessage(99).Data

Will send message 99 to the user. This is the exact same as using this code:

ConBuf.PreAllocate 2
ConBuf.Put_Byte DataCode.Server_Message
ConBuf.Put_Byte 99
Data_Send ToIndex, UserIndex, ConBuf.Get_Buffer

But using the cached message is a lot faster since the byte array is already made and the conversion buffer doesn't have to be used as a medium to create it.

[edit] Non-cached

Messages that have parameters must be created this way because of the extra fields they offer. You can pass as many parameters of any type you want, but the client must know what to grab. For example, you can send a message with no parameters:

ConBuf.PreAllocate 2
ConBuf.Put_Byte DataCode.Server_Message
ConBuf.Put_Byte 99
Data_Send ToIndex, UserIndex, ConBuf.Get_Buffer

Or a message with some parameters:

ConBuf.PreAllocate 5 + Len(ObjData.Name(QuestData(NPCList(QuestNPC).Quest).AcceptReqObj))
ConBuf.Put_Byte DataCode.Server_Message
ConBuf.Put_Byte 63
ConBuf.Put_Integer QuestData(NPCList(QuestNPC).Quest).AcceptReqObjAmount
ConBuf.Put_String ObjData.Name(QuestData(NPCList(QuestNPC).Quest).AcceptReqObj)
Data_Send ToIndex, UserIndex, ConBuf.Get_Buffer

Keep in mind you will have to denote where these parameters go in the message file, such as using <> tags like vbGORE does by default. As long as the client knows what parameters are there, and what they mean, you can send whatever you want.

[edit] On the client

All the server message handling that you need to worry about happens in Sub Data_Server_Message. For your message, add a new Case anywhere you want in the Select Case block, with the case number being the ID number of your message.

If you do not have any parameters, like message 99, you can just go straight to handling the message. Usually, this is just displaying the message in the message box:

Case 99
    Engine_AddToChatTextBuffer Message(99), FontColor_Info

But if you have parameters, you must grab them out first before doing anything:

Case 63
    Int1 = rBuf.Get_Integer
    Str1 = rBuf.Get_String
    TempStr = Replace$(Message(63), "<amount>", Int1)
    Engine_AddToChatTextBuffer Replace$(TempStr, "<name>", Str1), FontColor_Info

As you can see, for each parameter, there is a Replace$() function. The unaltered message starts in the variable Message(63). The altered message, the one that holds are variable replacements, is held in the TempStr variable. As you can see, you simply just enter in the variable name you wish to replace from your message, and the variable you wish to replace it with. For example, <amount> is being replaced with Int1, which was our first parameter.

Personal tools