learn dbEntry FIRST.. make a program and just keep displaying it: dbPrint(dbEntry) in your loop... and type stuff.
It keeps growing until you dbClearEntryBuffer();
tab = (char)10
Enter=(char)13
You may or maynot see those in this test. Bottom line... its a buffer.
in your loop you copy this buffer to your own string... (what the person it typing).... then you empty the buffer. As you are moving the data into the buffer (preferably char by char in this case.. test for (char)13 ... (enter)... If found... Send what ya have RIGHT THERE to the network, clear your own buffer, and continue the copy from the dbEntry.
Once you copied all the letters etc from dbEntry... dbClearEntryBuffer(); So it doesn't keep growing even though you already processed it. DarkGDK wrote it this way so you can get all the "chars typed" by the user regardless how fast they typed them... (while...) during your game code... so when your code comes back.. you look in buffer... you might have 1 char, or 100!
But DUDE?!?!? How do I copy the dbEntry() thing to my own buffer if its a function call? How do I loop through it? Call it over and over? YIKES!
this is MY way... not necessarily the "right" way LOL...
first make a buffer... I personally make one, 1k long, in a namespace for these kidns of tasks...
char buf[1024];
1024 might be to big.. who knows
then you need to research the strcpy command to copy dbEntry to your buffer. Then you can iterate though this buffer a char at a time and copy to bytes to your screen and a chat line buffer...
char chatbuf[1024]
and during this loop copying char by char from buffer to charbuffer.. when you encounter the char(13) (enter key) or hit the 1024 mark.. Send the text via inet. Set chat buffer to all zeroes so its "clean and empty"... continue loop until you finished reading from "buf". Done? Clean and Empty "buf" to all zeroes.
This is a safe way to do it. I have a way that could accomplish the same thing in my DarkGDK OOP lib...
http://code.google.com/p/darkgdk/ but its basically because I have my own string lib in there to ease this sort of thing, likewise C++ comes with the "STDLIB" that has various string functions to help ya... but you're on your own there.. at least from me.. most people use that method so the help will be here.. just I'm not versed enough with it myself to go on and on..
Good luck. BTW - I'm about to release a new and final release of my DarkGDK oop in next day or two and it has a fledgling gui system... and there is a code snip that does exactly what your trying to do ... using my string lib... and it looks like:
jgc_userinput.h from new DarkGDK OOP Lib not released yet...
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2007 Jegas, LLC
============================================================================*/
#pragma once
#include <DarkGDK.h>
#include "jfc_string.h"
#include "jgc_configuration.h"
#include "jgc_timer.h"
//============================================================================
class JGC_USERINPUT{
//============================================================================
public:
JGC_USERINPUT();
~JGC_USERINPUT();
void Update(int p_Timer);// Pass ZERO to bypass timerbased user input.
bool MouseEnabled;
JGC_TIMER *MouseTimer;
int MouseX;
int MouseY;
int MouseZ;
int MouseXOld;
int MouseYOld;
int MouseZOld;
int MouseMovedX;
int MouseMovedXOld;
int MouseMovedY;
int MouseMovedYOld;
int MouseMovedZ;
int MouseMovedZOld;
int MouseButtons; // Same as GDK dbMouseClick()
bool MouseButton1;
bool MouseButton1Old;
bool MouseButton2;
bool MouseButton2Old;
bool MouseButton3;
bool MouseButton3Old;
bool MouseButton4;
bool MouseButton4Old;
bool pvt_MouseVisible;
// Set to False Every Poll. To Avoid using
// using the same mouse polled data multiple times (think of the GUI)
// This flag can be used to invalidate the mouse input. Set to true
// when you have "Consumed" the values. This flag gets reset to TRUE
// when the Mouse is polled again.
bool MouseConsumed;
bool MouseVisible_Get(void);
void MouseVisible_Set(bool p_TrueOrFalse);
void pvt_ReadMouse(void);
//-----
bool ScanCodeConsumed;
int ScanCode;
//int ScanCodeOld;
JGC_TIMER *KeyBufferTimer;
void pvt_ReadKeyBuffer(void);
JFC_STRING *KeyBuffer;
bool KeyDown_LShift ;
bool KeyDown_RShift ;
bool KeyDown_Shift ; // Left OR Right
bool KeyDown_LWinKey ;
bool KeyDown_LAlt ;
bool KeyDown_RAlt ;
bool KeyDown_Alt ; //Left Or Right
bool KeyDown_RWinKey ;
bool KeyDown_WinMenu ;
bool KeyDown_LCntl ;
bool KeyDown_RCntl ;
bool KeyDown_Cntl ; //Left or Right
bool KeyDown_PrintScreen ;
bool KeyDown_ScrollLock ;
bool KeyDown_Break ;
bool KeyDown_Ins ;
bool KeyDown_Del ;
bool KeyDown_Home ;
bool KeyDown_End ;
bool KeyDown_PgUp ;
bool KeyDown_PgDn ;
bool KeyDown_UpArrow ;
bool KeyDown_DownArrow ;
bool KeyDown_LeftArrow ;
bool KeyDown_RightArrow ;
bool KeyDown_X ;//Cut
bool KeyDown_C ;//copy
bool KeyDown_V ;//paste
bool KeyDown_Z ;//Undo
bool KeyDown_Y ;//Redo
bool KeyDown_W ;// FPS Forward
bool KeyDown_A ;// FPS Left
bool KeyDown_S ;// FPS Backwards
bool KeyDown_D ;// FPS Right
bool KeyDown_Tab ;
/*
bool KeyDownOld_LShift ;
bool KeyDownOld_RShift ;
bool KeyDownOld_LWinKey ;
bool KeyDownOld_LAlt ;
bool KeyDownOld_RAlt ;
bool KeyDownOld_RWinKey ;
bool KeyDownOld_WinMenu ;
bool KeyDownOld_LCntl ;
bool KeyDownOld_RCntl ;
bool KeyDownOld_PrintScreen ;
bool KeyDownOld_ScrollLock ;
bool KeyDownOld_Break ;
bool KeyDownOld_Ins ;
bool KeyDownOld_Del ;
bool KeyDownOld_Home ;
bool KeyDownOld_End ;
bool KeyDownOld_PgUp ;
bool KeyDownOld_PgDn ;
bool KeyDownOld_UpArrow ;
bool KeyDownOld_DownArrow ;
bool KeyDownOld_LeftArrow ;
bool KeyDownOld_RightArrow ;
*/
};
//============================================================================
jgc_userinput.cpp from new DarkGDK OOP Lib not released yet...
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2007 Jegas, LLC
============================================================================*/
#include "jgc_userinput.h"
#include "jgc_common.h"
//============================================================================
// begin JFC_USERINPUT
//============================================================================
//----------------------------------------------------------------------------
JGC_USERINPUT::JGC_USERINPUT(){
//----------------------------------------------------------------------------
MouseEnabled=true;
MouseTimer=JGC::TimerArray->AppendItem_Timer();
MouseTimer->Set(DEFAULT_POLL_DELAY_MOUSE,dbTimer());
MouseX=0;
MouseY=0;
MouseZ=0;
MouseXOld=0;
MouseYOld=0;
MouseZOld=0;
MouseMovedX=0;
MouseMovedXOld=0;
MouseMovedY=0;
MouseMovedYOld=0;
MouseMovedZ=0;
MouseMovedZOld=0;
MouseButton1=false;
MouseButton1Old=false;
MouseButton2=false;
MouseButton2Old=false;
MouseButton3=false;
MouseButton3Old=false;
MouseButton4=false;
MouseButton4Old=false;
pvt_MouseVisible=true;
MouseConsumed=false;
KeyBufferTimer=JGC::TimerArray->AppendItem_Timer();
KeyBufferTimer->Set(DEFAULT_POLL_DELAY_KEYBOARD,dbTimer());
ScanCodeConsumed=false;
ScanCode=0;
KeyBuffer=new JFC_STRING();
KeyDown_LShift = false;
KeyDown_RShift = false;
KeyDown_Shift = false;
KeyDown_LWinKey = false;
KeyDown_LAlt = false;
KeyDown_RAlt = false;
KeyDown_Alt = false;
KeyDown_RWinKey = false;
KeyDown_WinMenu = false;
KeyDown_LCntl = false;
KeyDown_RCntl = false;
KeyDown_Cntl = false;
KeyDown_PrintScreen = false;
KeyDown_ScrollLock = false;
KeyDown_Break = false;
KeyDown_Ins = false;
KeyDown_Del = false;
KeyDown_Home = false;
KeyDown_End = false;
KeyDown_PgUp = false;
KeyDown_PgDn = false;
KeyDown_UpArrow = false;
KeyDown_DownArrow = false;
KeyDown_LeftArrow = false;
KeyDown_RightArrow = false;
KeyDown_X = false;
KeyDown_C = false;
KeyDown_V = false;
KeyDown_Z = false;
KeyDown_Y = false;
KeyDown_W = false;
KeyDown_A = false;
KeyDown_S = false;
KeyDown_D = false;
KeyDown_Tab = false;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
JGC_USERINPUT::~JGC_USERINPUT(){
//----------------------------------------------------------------------------
delete MouseTimer;
delete KeyBufferTimer;
delete KeyBuffer;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Pass ZERO to bypass timerbased user input.
void JGC_USERINPUT::Update(int p_Timer){
//----------------------------------------------------------------------------
if(MouseEnabled){
if((p_Timer==0)||(MouseTimer->DelayPassed(p_Timer))){
this->pvt_ReadMouse();
};
};
if((p_Timer==0)||(KeyBufferTimer->DelayPassed(p_Timer))){
this->pvt_ReadKeyBuffer();
};
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_USERINPUT::pvt_ReadMouse(void){
//----------------------------------------------------------------------------
MouseConsumed=false;
MouseXOld=MouseX;
MouseYOld=MouseY;
MouseZOld=MouseZ;
MouseX=dbMouseX();
MouseY=dbMouseY();
MouseZ=dbMouseZ();
MouseMovedXOld=MouseMovedX;
MouseMovedX=MouseX-MouseXOld;
MouseMovedYOld=MouseMovedY;
MouseMovedY=MouseY-MouseYOld;
MouseMovedZOld=MouseMovedZ;
MouseMovedZ=MouseZ-MouseZOld;
MouseButtons = dbMouseClick();
MouseButton1Old=MouseButton1;
MouseButton1=((MouseButtons & 1)==1);
MouseButton2Old=MouseButton2;
MouseButton2=((MouseButtons & 2)==2);
MouseButton3Old=MouseButton3;
MouseButton3=((MouseButtons & 4)==4);
MouseButton4Old=MouseButton4;
MouseButton4=((MouseButtons & 8)==8);
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool JGC_USERINPUT::MouseVisible_Get(void){
//----------------------------------------------------------------------------
return this->pvt_MouseVisible;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_USERINPUT::MouseVisible_Set(bool p_TrueOrFalse){
//----------------------------------------------------------------------------
this->pvt_MouseVisible=p_TrueOrFalse;
if(p_TrueOrFalse){
dbShowMouse();
}else{
dbHideMouse();
};
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_USERINPUT::pvt_ReadKeyBuffer(void){
//----------------------------------------------------------------------------
char *ss=dbEntry();
if(ss!=0){
this->KeyBuffer->ConCat(ss);
dbClearEntryBuffer();
};
this->ScanCodeConsumed=false;
this->ScanCode=dbScanCode();
KeyDown_LShift = dbKeyState(Key_LShift );
KeyDown_RShift = dbKeyState(Key_RShift );
KeyDown_Shift = (KeyDown_LShift || KeyDown_RShift);
KeyDown_LWinKey = dbKeyState(Key_LWinKey );
KeyDown_LAlt = dbKeyState(Key_LAlt );
KeyDown_RAlt = dbKeyState(Key_RAlt );
KeyDown_Alt = (KeyDown_LAlt || KeyDown_RAlt);
KeyDown_RWinKey = dbKeyState(Key_RWinKey );
KeyDown_WinMenu = dbKeyState(Key_WinMenu );
KeyDown_LCntl = dbKeyState(Key_LCntl );
KeyDown_RCntl = dbKeyState(Key_RCntl );
KeyDown_Cntl = (KeyDown_LCntl || KeyDown_RCntl);
KeyDown_PrintScreen = dbKeyState(Key_PrintScreen);
KeyDown_ScrollLock = dbKeyState(Key_ScrollLock );
KeyDown_Break = dbKeyState(Key_Break );
KeyDown_Ins = dbKeyState(Key_Ins );
KeyDown_Del = dbKeyState(Key_Del );
KeyDown_Home = dbKeyState(Key_Home );
KeyDown_End = dbKeyState(Key_End );
KeyDown_PgUp = dbKeyState(Key_PgUp );
KeyDown_PgDn = dbKeyState(Key_PgDn );
KeyDown_UpArrow = dbKeyState(Key_UpArrow );
KeyDown_DownArrow = dbKeyState(Key_DownArrow );
KeyDown_LeftArrow = dbKeyState(Key_LeftArrow );
KeyDown_RightArrow = dbKeyState(Key_RightArrow );
KeyDown_X = dbKeyState(Key_X);//cut
KeyDown_C = dbKeyState(Key_C);//copy
KeyDown_V = dbKeyState(Key_V);//paste
KeyDown_Z = dbKeyState(Key_Z);//Undo
KeyDown_Y = dbKeyState(Key_Y);//Redo
KeyDown_W = dbKeyState(Key_W);// FPS Forward
KeyDown_A = dbKeyState(Key_A);// FPS Left
KeyDown_S = dbKeyState(Key_S);// FPS Backwards
KeyDown_D = dbKeyState(Key_D);// FPS Right
KeyDown_Tab = dbKeyState(Key_Tab);
};
//----------------------------------------------------------------------------
//============================================================================
// end JFC_USERINPUT
//============================================================================
Good Luck Man!