Profilo di DexterC# Network library proje...FotoBlogElenchi Strumenti Guida

Blog


29 settembre

What to send and how?


What kinds of data I can send using Z-Communicator?  Well, the most common things comes to my mind is sending text messages, but that's not the only thing I need to send particularly in games, I also need to send int, float,bool etc... Ok, for this kind of data I created a Meta data type to send group of  fields with different kinds of data type in any order, I can also send raw bytes and serialized object, It can easily done by using the following data writers as shown below.

The sender manager members:

SenderMngr.PNG

Complete Overview

 

Data writers class members:

DataWriters.JPG



//!*>>> Prepares data writers..
//
ZNC.TextDataWriter     _TextDataWriter   =  new ZNC.TextDataWriter();     _TextDataWriter.SetDefault();
ZNC.MetaDataWriter    _MetaDataWriter   =  new ZNC.MetaDataWriter();    _MetaDataWriter.SetDefault();
ZNC.BytesDataWriter   _ByteDataWriter   =  new ZNC.BytesDataWriter();   _ByteDataWriter.SetDefault();
ZNC.ObjectDataWriter  _ObjDataWriter    =  new ZNC.ObjectDataWriter();  _ObjDataWriter.SetDefault();


// Sample user defined game commands, for the recipient to understand what the message is all about.
int _CHAT              = 50;
int _ENTITY_MPOS  = 51;
int _ENTITY_OPOS  = 52;

// Just for this simple example, I'll send the data to the first player at the lobby.
uint m_PlayerUID = _Server.LobbyMngr.GetPlayer(0).PlayerUID;




//!*>>>  S E N D I N G   T E X T   D A T A
//               
//  User defined game command
_TextDataWriter.Command  = _CHAT;
//
// Writing text data.
_TextDataWriter.TEXTDATA = "Hello";
//
// Sending text data using _TextDataWriter.
_Server.SenderMngr.SendTextData(  _TextDataWriter, 
m_PlayerUID,   false, false, false  );




//!*>> > S E N D I N G   M E T A   D A T A
//
//  Sample meta data.

int           m_Status   = 1;
XF.Point    m_Pos      = new XF.Point( 100, 100 );
float         m_VelX     = 0.2f;
float         m_VelY     = 0;
float         m_Speed   = 0.05f;
//
// User defined game command
_MetaDataWriter.Command   = _ENTITY_MPOS;
//
// Writing meta data
_MetaDataWriter.BeginWriteMetaData();
     _MetaDataWriter.WriteData( m_Status   );
     _MetaDataWriter.WriteData( m_Pos       );
     _MetaDataWriter.WriteData( m_VelX      );
     _MetaDataWriter.WriteData( m_VelY      );
     _MetaDataWriter.WriteData( m_Speed    );
_MetaDataWriter.EndWriteMetaData();
//
// Sending meta data using _MetaDataWriter.

_Server.SenderMngr.SendMetaData(  _MetaDataWriter, m_PlayerUID,  false,false,false  );




//!*>>> S E N D I N G   R A W B Y T E S   D A T A
//               

// Sample bytes data.
string m_ConvertMe   = "Send me as bytes";               
//
// Game user defined command
_BytesDataWriter.Command    = 0;
//
// Writing raw bytes.
_ByteDataWriter.BYTESDATA = STE.ASCII.GetBytes(  m_ConvertMe.ToCharArray()  );
//
// Sending raw bytes using _ByteDataWriter.
_Server.SenderMngr.SendBytesData(  _ByteDataWriter, m_PlayerUID,  false, false, false  );




//!*>>>  S E N D I N G   O B J E C T   D A T A
//
// Sample serialized object class. 

SerialObj m_SerialObj = new SerialObj();
//
m_SerialObj.Status  = 1;
m_SerialObj.Pos      = new XF.Point( 100, 100 );
m_SerialObj.VelX     = 0.2f;
m_SerialObj.VelY     = 0;
m_SerialObj.Speed   = 0.05f;
//
// User defined game command
_ObjDataWriter.Command       = _ENTITY_OPOS;
//
// Writing object data.

_ObjDataWriter.OBJECTDATA = m_SerialObj;
//
// Sending object data using _ObjDataWriter.
_Server.SenderMngr.SendObjectData(  _ObjDataWriter, m_PlayerUID,  false, false, false  );




That's how easy it is to send text, meta data, bytes and object data types to the recipient, the samples above uses only the sending overload on a particular client, tho, I can also send data to all or selected player/s at the lobby, send to all or selected player/s on a particular game, send to all or selected player/s on a particular game session and even send to all or selected players/s on a particular zone or area in just a single line, as shown below :


//! Sample single and selected player's UID list..
uint   m_PlayerUID = 1001;
uint[] m_PListUIDS = new uint[] { 1001,1002,1003 };

_TextDataWriter.TEXTDATA = "Hello";

// Say hello to all players. 
_Server.SenderMngr.SendTextData(  _TextDataWriter, 
false, false, false  );
// Say hello to a particular player
.
_Server.SenderMngr.SendTextData(  _TextDataWriter, 
m_PlayerUID,   false, false, false  );
// Say hello to selected  players.
_Server.SenderMngr.SendTextData(  _TextDataWriter, 
m_PListUIDS,   false, false, false  );

// Say hello to all player on  a particular game.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnGame,     
m_GameUID,  null, false, false, false );
// Say hello to selected players on a particular game
.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnGame,     
m_GameUID,  m_PListUIDS,  false, false, false  );

// Say hello to all player on  a particular session.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnSession, 
m_SessionUID null, false, false, false );
// Say hello to selected players on a particular session
.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnSession, 
m_SessionUID,  m_PListUIDS, false, false, false  );

// Say hello to all player on  a particular zone or area.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnZone,       
m_ZoneUID,  null, false, false, false );
// Say hello to selected players on a particular zone or area
.
_Server.SenderMngr.SendTextData(  _TextDataWriter,  ZNE.SendTo.PlayerOnZone,     
m_ZoneUID,  m_PListUIDS,  false, false, false );






Commenti

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

Riferimenti

L'URL di riferimento per questo intervento è:
http://dexterz.spaces.live.com/blog/cns!9E6C0341ABD0C595!257.trak
Blog che fanno riferimento a questo intervento
  • Nessuno