ChatBlade How To Documentation
How To Design a Chat Server

Related ChatBlade Classes and functions:  
    CBSampleChatServer.java
    CBSampleChatServerApp.java
    CBMultiTasker.java

 
Summary:  
  Jump to section   Create a Chat Server Application.  
  Jump to section Hook the Chat Server up to the Games Networking.    
  Jump to section Hook the Chat Server up to the Games Database.  
  Jump to section Parse each incoming Chat Message and determine its recipients.  
  Jump to section Forward each Chat Message to the Players who should receive it.  
  Jump to section Inform the Sender of any errors (Player not online, etc.  ).  
 

 
Details:  
 
Create a Chat Server Application.  
     ChatBlade does not come with a production Chat Server included.  
Since each Game using ChatBlade may have different Networking and Database structures, it is up to each Game Developer to create a Chat Server that works with their Networking and Game Database.  
ChatBlade ships with a Sample Chat Server written in Java (to allow testing on different platforms) which outlines how a Chat Server may function (primarily by using SQL pseudo-code).  
In order to have a functioning Chat System, each Game shall need to create a Chat Server component.  
ChatBlade has been designed to make the Creation of this Chat Server as simple as possible.  
It is recommended that Back-up, redundant Chat Servers be running in case the primary Chat Servers go down.  
A Chat Server just needs to look at each incoming Chat Message, figure out who to forward that message to (based on the Chat Channel and Destination), and then forward the Chat Messages to its correct recipients.  
Optionally a Chat Server can be designed more intricately to include real-time monitoring, display, and logging or Game Chat.  
For a sample Chat Server implementation, see the .java files in the ChatBlade\Source\CBSampleChatServer directory.  
 
Hook the Chat Server up to the Games Networking.  
     Each Game may utilize differing Networking (using sockets or Network Middleware).  
A Chat Server needs to receive Chat Messages over the wire and then forward those Chat Messages to the various Player Game Clients which should receive the Chat Messages.  
Game Clients should never talk peer-to-peer and should only communicate via a Chat Server to help improve Game Security.  
In addition, for securities sake, each Network packet should be encrypted when coming into and out of the Chat Server.  
A Chat Server should decrypt the Chat Message to parse it, then re-encrypt it when forwarding it to its recipients.  
The Sample Chat Server (and associated CBChatSampleNetworkClient) contain rudimentary encryption that is initially disabled to allow for ease of debugging.  
See CBChatSampleNetworkClient and  CBSampleChatServer.java for Sample Code.  
 
Hook the Chat Server up to the Games Database.  
     Each Game shall utilize a different Database Schema.  
A Chat Server needs to know which Players are in which Groups, Guilds, Raids, and Alliances.  
In addition, a Chat Server may need to know which Players are nearby a Character sending a /say or /emote Chat Message.  
It is envisioned that a Chat Server would obtain this information from the Game Database for each Chat Message that needs to be distributed.  
Alternatively the Chat Server could be designed to cache this information.  In that case it would need to be informed whenever Group membership changed or when Players logged on or off.  
The Sample Chat Server contains rudimentary SQL pseudo-code describing what the Database lookups may look like for each Chat Channel.  
 
Parse each incoming Chat Message and determine its recipients.  
     Each incoming Chat Message should have a Source, Destination, and Chat Channel.  
Using this information a Chat Server should be able to determine which Characters should receive a Chat Message.  
Using the Chat Channel and Destination, a list of recipients should be able to be determined.  
For example:  Chat Messages on the CB_CHANNEL_GROUP Chat Channel have their Destination set as the GROUPID of the Group.  
    A Chat Server should then lookup all members of this GroupID and form a list.  
    Similarly, Chat Messages on the CB_CHANNEL_GUILD have the GuildID as the Destination.  
        A Chat Server would then form a list of all online Characters that are members of this Guild.  
    Chat Messages on the CB_CHANNEL_TELL have a single Character name as the Destination of the Chat Message.  
        A Chat Server would then get the IPAddress or Network Handle of the Character who should get the /tell.  
Chat Messages that should be sent to Characters that are near the Sender (such as /say or /emote) are a bit more difficult.  
A Chat Server may need to do a Database lookup and find all nearby Characters to the Sender.  
    Alternatively, if the Game Client already knows which Characters are nearby, then CBSlashCommands::ProcessSayTypeCommand() could be modified to send a /tell style Chat Message to each nearby Character, thereby offloading some of the Server work to the Client.  
See CBSampleChatServer.java for pseudo-code samples of how to handle each Chat Channel.  
Sample Code:  
 
Forward each Chat Message to the Players who should receive it.  
     Once a list of recipients of a Chat Message is formed the Chat Server should re-encrypt the Chat Message and forward it over the wire to the correct Characters.  
A list of recipients may just be an array of IPAddresses, or if the Games Networking is more complex, then it might entail Network Handles for various Network Middleware packages.  
ChatBlade takes care of /Ignore functionality in the Game Client, and it does not need to be incorporated into the Chat Server.  
ChatBlade also takes care of Chat Channel Monitoring in the Client, and such filtering does not need to be done in the Chat Server.  
    For Example:  CB_CHANNEL_AUCTION Chat Messages should be sent to each online Character in the Region or Server (depending on Game Design).  If a Player is not monitoring the Auction Chat Channel, then ChatBlade shall discard the Chat Message in the Client.  
Most Chat Messages (such as /group, /guild, /auction, etc.  ) should be sent back to their sender for Display.  
 
Inform the Sender of any errors.  
     A Chat Server should also inform the Sender of a Chat Message of any errors encountered.  
For example, a Player might send a /tell to a Character who is not online or does not exist (misspelled).  
In this case the Chat Server should create a Chat Message response and tell the Sender of their error.  
ChatBlade tries to prevent Chat Messages going out to Groups, Guilds, Raids, and Alliances when the Sender is not a member of such entities.  
 

 

Code Samples:  

Getting a list of the recipients for a Group Chat Message.  
     // Get the IPADDRESSES of all Group members
case CB_CHANNEL_GROUP:
case CB_CHANNEL_GROUP_PRIORITY:
rsResultSet = stSQLStatement.executeQuery(("SELECT IPAddress FROM GroupList WHERE GroupName = " + sDestination));
break;
 
    
 
    
    
 
    
 
    

 

 

 

 

 

 
 
 
 
ChatBlade Copyright Flex Dolphynn