Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

sv_net_chan.c File Reference

#include "../game/q_shared.h"
#include "../qcommon/qcommon.h"
#include "server.h"

Include dependency graph for sv_net_chan.c:

Include dependency graph

Go to the source code of this file.

Functions

void SV_Netchan_Decode (client_t *client, msg_t *msg)
void SV_Netchan_Encode (client_t *client, msg_t *msg)
qboolean SV_Netchan_Process (client_t *client, msg_t *msg)
void SV_Netchan_Transmit (client_t *client, msg_t *msg)
void SV_Netchan_TransmitNextFragment (client_t *client)


Function Documentation

void SV_Netchan_Decode client_t client,
msg_t msg
[static]
 

Definition at line 90 of file sv_net_chan.c.

References msg_t::bit, byte, client_s::challenge, client_t, msg_t::cursize, msg_t::data, i, MAX_RELIABLE_COMMANDS, MSG_ReadLong(), msg_t::oob, msg_t::readcount, client_s::reliableCommands, and string().

Referenced by SV_Netchan_Process().

00090                                                               {
00091     int serverId, messageAcknowledge, reliableAcknowledge;
00092     int i, index, srdc, sbit, soob;
00093     byte key, *string;
00094 
00095         srdc = msg->readcount;
00096         sbit = msg->bit;
00097         soob = msg->oob;
00098         
00099         msg->oob = 0;
00100         
00101         serverId = MSG_ReadLong(msg);
00102     messageAcknowledge = MSG_ReadLong(msg);
00103     reliableAcknowledge = MSG_ReadLong(msg);
00104 
00105         msg->oob = soob;
00106         msg->bit = sbit;
00107         msg->readcount = srdc;
00108         
00109     string = (byte *)client->reliableCommands[ reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ];
00110     index = 0;
00111     //
00112     key = client->challenge ^ serverId ^ messageAcknowledge;
00113     for (i = msg->readcount + SV_DECODE_START; i < msg->cursize; i++) {
00114         // modify the key with the last sent and acknowledged server command
00115         if (!string[index])
00116             index = 0;
00117         if (string[index] > 127 || string[index] == '%') {
00118             key ^= '.' << (i & 1);
00119         }
00120         else {
00121             key ^= string[index] << (i & 1);
00122         }
00123         index++;
00124         // decode the data with this key
00125         *(msg->data + i) = *(msg->data + i) ^ key;
00126     }
00127 }

Here is the call graph for this function:

void SV_Netchan_Encode client_t client,
msg_t msg
[static]
 

Definition at line 36 of file sv_net_chan.c.

References msg_t::bit, byte, client_s::challenge, client_t, msg_t::cursize, msg_t::data, i, client_s::lastClientCommandString, MSG_ReadLong(), client_s::netchan, msg_t::oob, netchan_t::outgoingSequence, msg_t::readcount, and string().

Referenced by SV_Netchan_Transmit(), and SV_Netchan_TransmitNextFragment().

00036                                                               {
00037     long reliableAcknowledge, i, index;
00038     byte key, *string;
00039         int srdc, sbit, soob;
00040         
00041     if ( msg->cursize < SV_ENCODE_START ) {
00042         return;
00043     }
00044 
00045         srdc = msg->readcount;
00046         sbit = msg->bit;
00047         soob = msg->oob;
00048         
00049         msg->bit = 0;
00050         msg->readcount = 0;
00051         msg->oob = 0;
00052         
00053     reliableAcknowledge = MSG_ReadLong(msg);
00054 
00055         msg->oob = soob;
00056         msg->bit = sbit;
00057         msg->readcount = srdc;
00058         
00059     string = (byte *)client->lastClientCommandString;
00060     index = 0;
00061     // xor the client challenge with the netchan sequence number
00062     key = client->challenge ^ client->netchan.outgoingSequence;
00063     for (i = SV_ENCODE_START; i < msg->cursize; i++) {
00064         // modify the key with the last received and with this message acknowledged client command
00065         if (!string[index])
00066             index = 0;
00067         if (string[index] > 127 || string[index] == '%') {
00068             key ^= '.' << (i & 1);
00069         }
00070         else {
00071             key ^= string[index] << (i & 1);
00072         }
00073         index++;
00074         // encode the data with this key
00075         *(msg->data + i) = *(msg->data + i) ^ key;
00076     }
00077 }

Here is the call graph for this function:

qboolean SV_Netchan_Process client_t client,
msg_t msg
 

Definition at line 199 of file sv_net_chan.c.

References client_t, client_s::netchan, Netchan_Process(), qboolean, and SV_Netchan_Decode().

Referenced by SV_PacketEvent().

00199                                                             {
00200     int ret;
00201     ret = Netchan_Process( &client->netchan, msg );
00202     if (!ret)
00203         return qfalse;
00204     SV_Netchan_Decode( client, msg );
00205     return qtrue;
00206 }

Here is the call graph for this function:

void SV_Netchan_Transmit client_t client,
msg_t msg
 

Definition at line 174 of file sv_net_chan.c.

References client_t, Com_DPrintf(), msg_t::cursize, msg_t::data, netchan_buffer_s::msg, MSG_Copy(), MSG_WriteByte(), netchan_buffer_s::msgBuffer, client_s::netchan, netchan_buffer_t, client_s::netchan_end_queue, Netchan_Transmit(), Netchan_TransmitNextFragment(), netchan_buffer_s::next, SV_Netchan_Encode(), svc_EOF, netchan_t::unsentFragments, and Z_Malloc().

Referenced by SV_SendMessageToClient().

00174                                                         {   //int length, const byte *data ) {
00175     MSG_WriteByte( msg, svc_EOF );
00176     if (client->netchan.unsentFragments) {
00177         netchan_buffer_t *netbuf;
00178         Com_DPrintf("#462 SV_Netchan_Transmit: unsent fragments, stacked\n");
00179         netbuf = (netchan_buffer_t *)Z_Malloc(sizeof(netchan_buffer_t));
00180         // store the msg, we can't store it encoded, as the encoding depends on stuff we still have to finish sending
00181         MSG_Copy(&netbuf->msg, netbuf->msgBuffer, sizeof( netbuf->msgBuffer ), msg);
00182         netbuf->next = NULL;
00183         // insert it in the queue, the message will be encoded and sent later
00184         *client->netchan_end_queue = netbuf;
00185         client->netchan_end_queue = &(*client->netchan_end_queue)->next;
00186         // emit the next fragment of the current message for now
00187         Netchan_TransmitNextFragment(&client->netchan);
00188     } else {
00189         SV_Netchan_Encode( client, msg );
00190         Netchan_Transmit( &client->netchan, msg->cursize, msg->data );
00191     }
00192 }

Here is the call graph for this function:

void SV_Netchan_TransmitNextFragment client_t client  ) 
 

Definition at line 134 of file sv_net_chan.c.

References client_t, Com_DPrintf(), Com_Error(), msg_t::cursize, msg_t::data, ERR_DROP, netchan_buffer_s::msg, client_s::netchan, netchan_buffer_t, client_s::netchan_end_queue, client_s::netchan_start_queue, Netchan_Transmit(), Netchan_TransmitNextFragment(), netchan_buffer_s::next, SV_Netchan_Encode(), netchan_t::unsentFragments, and Z_Free().

Referenced by SV_SendClientMessages().

00134                                                          {
00135     Netchan_TransmitNextFragment( &client->netchan );
00136     if (!client->netchan.unsentFragments)
00137     {
00138         // make sure the netchan queue has been properly initialized (you never know)
00139         if (!client->netchan_end_queue) {
00140             Com_Error(ERR_DROP, "netchan queue is not properly initialized in SV_Netchan_TransmitNextFragment\n");
00141         }
00142         // the last fragment was transmitted, check wether we have queued messages
00143         if (client->netchan_start_queue) {
00144             netchan_buffer_t *netbuf;
00145             Com_DPrintf("#462 Netchan_TransmitNextFragment: popping a queued message for transmit\n");
00146             netbuf = client->netchan_start_queue;
00147             SV_Netchan_Encode( client, &netbuf->msg );
00148             Netchan_Transmit( &client->netchan, netbuf->msg.cursize, netbuf->msg.data );
00149             // pop from queue
00150             client->netchan_start_queue = netbuf->next;
00151             if (!client->netchan_start_queue) {
00152                 Com_DPrintf("#462 Netchan_TransmitNextFragment: emptied queue\n");
00153                 client->netchan_end_queue = &client->netchan_start_queue;
00154             }
00155             else
00156                 Com_DPrintf("#462 Netchan_TransmitNextFragment: remaining queued message\n");
00157             Z_Free(netbuf);
00158         } 
00159     }   
00160 }

Here is the call graph for this function:


Generated on Thu Aug 25 15:32:51 2005 for Quake III Arena by  doxygen 1.3.9.1