|
CBChatSampleNetworkClient::CBChatSampleNetworkClient() |
|
|
Comments: |
Empty Constructor. |
|
|
|
|
|
|
int |
CBChatSampleNetworkClient::InitializeNetwork() |
|
|
Comments: |
Initializes various Networking components. |
Sets up our Sockets. Initializes Winsock.
Sets our ports and Chat Server Address. Starts up
our receiving Thread. |
Should be called before doing any actions involving
the Network. |
Called from CBSampleImplementation::InitializeChatNetworking(). |
|
|
|
|
|
|
int |
CBChatSampleNetworkClient::DeInitializeNetwork() |
|
|
Comments: |
Closes our Sockets and Cleans up WinSock. Sets m_bKeepListeningFlag
to FALSE. |
Should be called once the Client is shutting
down. |
|
|
|
|
|
|
static unsigned __stdcall |
CBChatSampleNetworkClient::ThreadedReceiveFunction( |
void * pArguments) |
|
Comments: |
Function implemented in its own Thread in order to
receive Chat Network packets. |
This function listens for packets on the UDP port
specified by m_ReceivingSocket. Packets must come
from a valid Chat Server IP address. |
When a packet is received this function allocates
space for the data and decrypts it. |
It then passes the data to the main application via a
PostMessage() Win32 call with the ID of WM_USER_CB_MESSAGE
along with a pointer to the allocated Chat
Message. This places the information on the
Windows Message Queue. |
It is up to the main Application to process this
Windows message and retrieve the data from the allocated
pointer and pass that information onto ChatBlade (via CBChatHandler::OnIncomingChatMessage()). |
It is important to free the memory for the
Pointer. Memory is allocated here in
ThreadedReceiveFunction() but should be freed in the
main Application after the Windows Message has been
processed. |
See OnChatMessageReceived() in the ChatBlade Sample
Test Client application (CBMFCTestClient). |
|
|
Parameters: |
pArguments |
Pointer to Void.
Not used. Just needed to match the
Threading requirements. |
|
|
|
|
|
|
|
|
static int |
CBChatSampleNetworkClient::IsValidChatServer( |
CBSTRING sAddress) |
|
Comments: |
This function verifies whether or not the
IP address given is that of a Valid Chat
Server. |
Used to authenticate received messages and
insure that they are not spoofed. |
If sAddress is an address previously
passed to AddValidChatServerAddress() this function
returns CB_TRUE. |
Called by ThreadedReceiveFunction() once
for each packet
received. |
|
|
Parameters: |
sAddress |
The IP Address of a
Network packet we want to Authenticate
against. |
|
|
|
|
|
Returns: |
CB_TRUE if sAddress is a valid Chat Server
address. |
CB_FALSE if sAddress is not on the list of valid Chat
Servers. |
|
|
|
int |
CBChatSampleNetworkClient::SendChatMessage( |
CBChatMessage cbChatMessage) |
|
Comments: |
Sends a Chat Message to the Chat Server via UDP over
the Internet. |
This function performs the actual network transmittal
of a Chat Message. |
First the CBChatMessage
parameter is converted to a String representation.
Then it is potentially encrypted. |
Finally it is sent via the UDP port specified by m_SendingPort
to the Chat Server indicated by m_CurrentChatServerAddress. |
The size of the packet is limited to CB_MAX_UDP_PACKET_SIZE. |
Called by CBSampleImplementation::SendChatMessage().
CBChatHandler::SendChatMessage()
is the function that should be invoked to start sending
a Chat Message to the Chat Server. |
It is up to the Chat Server to examine each message
and forward the Chat Message onto other Players based on
the Chat Channel and Destination contained in the
message. |
|
|
Parameters: |
cbChatMessage |
A CBChatMessage
instance of a Chat Message we want to send
out. |
|
|
|
|
|
Returns: |
CB_ERROR_UNICODE_CONVERSION if there is an error
converting strings when compiling under
UNICODE. |
CB_SUCCESS |
|
|
|
int |
CBChatSampleNetworkClient::ConvertChatMessageToNetworkString( |
CBChatMessage cbChatMessage
/*IN*/, |
|
|
CBSTRING & sNetworkString
/*OUT*/) |
|
Comments: |
Converts a CBChatMessage
instance into a String representation of that instance
to facilitate Network transmittal. |
Makes a string out of the CBChatMessage. |
A sample string looks like so: |
S=VANADIAD=IRRIDIAC=52M=0L=0F=0T=How much for the Sword? |
Called by SendChatMessage(). |
|
|
Parameters: |
|
sNetworkString |
A reference to a CBSTRING
that shall hold our string representation of the
Chat Message upon function return. |
|
|
|
|
Returns: |
CB_SUCCESS |
Upon return sNetworkString shall be filled with a
string representing the Chat Message. |
|
|
|
static int |
CBChatSampleNetworkClient::ConvertNetworkStringToChatMessage( |
CBChatMessage & cbChatMessage
/*OUT*/, |
|
|
CBSTRING sNetworkString
/*IN*/) |
|
Comments: |
Converts a string received from a Chat Server into a CBChatMessage
instance. |
Text is used to send packets over the Network.
This function converts from text into the CBChatMessage
class used by ChatBlade. |
A sample string initially looks like so: |
S=VANADIAD=IRRIDIAC=52M=0L=0F=0T=How much for the Sword? |
This function parses that string and fills in the data
fields of cbChatMessage. |
The string should already have any Network Encryption
removed. |
Called by OnChatMessageReceived() in the ChatBlade
Sample Test Client application (CBMFCTestClient). |
|
|
Parameters: |
cbChatMessage |
A reference to a
CBChatMessage instance which shall hold the data
from the Network string upon function
return. |
|
sNetworkString |
A decrypted string
received from the Chat Server representing a
Chat Message. |
|
|
|
|
Returns: |
CB_ERROR_INCOMPLETE_MESSAGE if the Chat Message is
malformed. |
CB_SUCCESS if the conversion was
successful. |
Upon successful return, cbChatMessage is filled with
data parsed from sNetworkString. |
|
|
|
int |
CBChatSampleNetworkClient::WireEncryptString( |
CBSTRING & sString
/*IN OUT*/) |
|
Comments: |
Encrypts a string prior to Network
transmittal. |
All data passing over the Internet should be encrypted
to enhance the security of an application. Raw
text makes things much simpler for any hacking
attempts. |
This function encrypts a Chat Message a random amount
of times using encryption Keys. |
The encryption found here must match the decryption in
the Chat Server. |
For development purposes the Random value can be hard
coded to 0 to disable any encryption so that the packets
may be monitored. |
The encryption provided by this function is
weak. It is designed to prevent raw text from
being sent over the Net. |
Called by SendChatMessage(). |
|
|
Parameters: |
sString |
A reference to a
string which shall be encrypted upon return of
the function. |
|
|
|
|
|
|
|
|
static int |
CBChatSampleNetworkClient::WireDecryptString( |
CBSTRING & sString
/*IN OUT*/) |
|
Comments: |
Decrypts a Network string and changes it into its
original text. |
All data passing over the Internet should be encrypted
to enhance the security of an application. Raw
text makes things much simpler for any hacking
attempts. |
This function Decrypts a string that had previously
been encrypted by WireEncryptString() or the Sample Chat
Server. |
Called by ThreadedReceiveFunction(). |
|
|
Parameters: |
sString |
A reference to an
Encrypted string. Upon function return the
string should be Decrypted. |
|
|
|
|
|
Returns: |
CB_ERROR_BAD_PARAMETER if the string is too
small. |
CB_SUCCESS |
|
|
|
int |
CBChatSampleNetworkClient::AddValidChatServerAddress( |
CBSTRING sAddress) |
|
Comments: |
Adds in an IPAddress of a valid Chat Server. |
Only Chat Messages received from valid Chat Servers
are processed by the ChatBlade Sample Network
code. |
Call this function with the IPAddress (IPv4)for each possible Chat Server. |
For Example: AddValidChatServerAddress(_T("184.47.22.1")); |
|
|
Parameters: |
sAddress |
The IPAddress of an
official Chat Server. |
|
|
|
|
|
|
|
|
int |
CBChatSampleNetworkClient::SetSendPort( |
int nPort) |
|
Comments: |
Sets the UDP Port number used when transmitting to the Chat Server. |
The actual port number used may be Byte Swapped.
For Example: Setting this to port 0x1984 may
actually transmit on port 0X8419. |
The Chat Server must be listening on this Port Number
in order to receive packets from the
Clients. |
|
|
Parameters: |
nPort |
The UDP Port number
used to send our Packets to the Chat
Server. |
|
|
|
|
|
|
|
|
int |
CBChatSampleNetworkClient::SetReceivePort( |
int nPort) |
|
Comments: |
Sets the UDP Port number to listen to in order to receive messages
from the Chat Server. |
The actual port number used may be Byte Swapped.
For Example: Setting this to port 0x1985 may
actually receive on port 0X8519. |
Two ports are used in the ChatBlade Network Sample,
one to receive and one to transmit. This allows
Developers to use one machine to test on. In
production Networking it may be advisable to use a
Single port. |
|
|
Parameters: |
nPort |
The UDP Port number to
listen to in order to receive Chat Messages from
the Chat Server. |
|
|
|
|
|
|
|
|
int |
CBChatSampleNetworkClient::SetCurrentChatServerAddress( |
CBSTRING sIPAddress) |
|
Comments: |
Sets the IP Address of the default Chat Server for this Client to send messages to. |
All Chat Messages using this Sample Networking shall
be sent to this Chat Server IP Address for Chat Message
propagation. |
|
|
Parameters: |
sIPAddress |
The IPAddress of a
Chat Server this client should use. |
|
|
|
|
|
|
|
|
|