Remove old and unauthorized cruft.
This commit is contained in:
parent
853d19e09b
commit
f5a91ffdc7
9 changed files with 0 additions and 784 deletions
|
@ -1,36 +0,0 @@
|
|||
noinst_LIBRARIES = libServer.a
|
||||
noinst_PROGRAMS = buftest msgtest
|
||||
|
||||
if ENABLE_MSERVER_AS
|
||||
|
||||
MSERVER_AS = \
|
||||
msg_0001_hello.cxx \
|
||||
msg_0001_hello.hxx \
|
||||
messagebuf.cxx \
|
||||
messagebuf.hxx \
|
||||
message.cxx \
|
||||
message.hxx
|
||||
|
||||
MSERVER_BUF = buftest.cxx
|
||||
|
||||
MSERVER_MSG = msgtest.cxx
|
||||
|
||||
else
|
||||
|
||||
MSERVER_AS =
|
||||
|
||||
MSERVER_BUF =
|
||||
|
||||
MSERVER_MSG =
|
||||
|
||||
endif
|
||||
|
||||
libServer_a_SOURCES = $(MSERVER_AS)
|
||||
|
||||
buftest_SOURCES = $(MSERVER_BUF)
|
||||
buftest_LDADD = libServer.a
|
||||
|
||||
msgtest_SOURCES = $(MSERVER_MSG)
|
||||
msgtest_LDADD = libServer.a
|
||||
|
||||
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
|
|
@ -1,140 +0,0 @@
|
|||
#include "message.hxx"
|
||||
|
||||
void dumpmessage(string msg)
|
||||
{
|
||||
FGMPSMessageBuf buf;
|
||||
|
||||
buf.set(msg);
|
||||
buf.ofs(0);
|
||||
|
||||
bool done=false;
|
||||
while (!done) {
|
||||
unsigned char mid8, uval8;
|
||||
unsigned int mid16, uval16;
|
||||
unsigned long uval32;
|
||||
unsigned long long uval64;
|
||||
char val8;
|
||||
int val16;
|
||||
long val32;
|
||||
long long val64;
|
||||
float valf;
|
||||
double vald;
|
||||
string vals;
|
||||
printf("dump: ");
|
||||
for (int i=0; i<16; i++) printf("%02x ", buf.peek(i));
|
||||
printf("\n");
|
||||
try {
|
||||
int tag = buf.get(true);
|
||||
switch (tag) {
|
||||
case fgmps_som8:
|
||||
mid8 = *(unsigned char *)buf.read1();
|
||||
printf("Start Message ID = %02x\n", mid8);
|
||||
break;
|
||||
case fgmps_som16:
|
||||
mid16 = *(unsigned int *)buf.read2();
|
||||
printf("Start Message ID = %04x\n", mid16);
|
||||
break;
|
||||
case fgmps_eom:
|
||||
printf("End Of Message\n", tag);
|
||||
done = true;
|
||||
break;
|
||||
case fgmps_uchar:
|
||||
uval8 = *(unsigned char *)buf.read1();
|
||||
printf("uchar = %02x\n", uval8);
|
||||
break;
|
||||
case fgmps_uint:
|
||||
uval16 = *(unsigned int *)buf.read2();
|
||||
printf("uint = %04x\n", uval16);
|
||||
break;
|
||||
case fgmps_ulong:
|
||||
uval32 = *(unsigned long *)buf.read4();
|
||||
printf("ulong = %08lx\n", uval32);
|
||||
break;
|
||||
case fgmps_ulonglong:
|
||||
uval64 = *(unsigned long long *)buf.read8();
|
||||
printf("ulonglong = %16llx\n", uval64);
|
||||
break;
|
||||
case fgmps_char:
|
||||
val8 = *(char *)buf.read1();
|
||||
printf("char = %02x\n", val8);
|
||||
break;
|
||||
case fgmps_int:
|
||||
val16 = *(int *)buf.read2();
|
||||
printf("int = %04x\n", val16);
|
||||
break;
|
||||
case fgmps_long:
|
||||
val32 = *(long *)buf.read4();
|
||||
printf("long = %08lx\n", val32);
|
||||
break;
|
||||
case fgmps_longlong:
|
||||
val64 = *(long long *)buf.read8();
|
||||
printf("longlong = %16llx\n", val64);
|
||||
break;
|
||||
case fgmps_float:
|
||||
valf = buf.readf();
|
||||
printf("float = %f\n", valf);
|
||||
break;
|
||||
case fgmps_double:
|
||||
vald = buf.readd();
|
||||
printf("double = %g\n", vald);
|
||||
break;
|
||||
case fgmps_string:
|
||||
uval8 = buf.get();
|
||||
vals = buf.reads(uval8);
|
||||
printf("string = %s\n", vals.c_str());
|
||||
break;
|
||||
default:
|
||||
printf("Unknown prefix = %02x\n", tag);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
} catch (FGMPSDataException e) {
|
||||
printf("Data Exception\n");
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FGMPSMessageBuf buf;
|
||||
|
||||
unsigned char uval8;
|
||||
unsigned int uval16;
|
||||
unsigned long uval32;
|
||||
unsigned long long uval64;
|
||||
char val8;
|
||||
int val16;
|
||||
long val32;
|
||||
long long val64;
|
||||
float valf;
|
||||
double vald;
|
||||
string vals;
|
||||
|
||||
buf.clr();
|
||||
buf.put(fgmps_som8, true);
|
||||
buf.put(1);
|
||||
for (int i=0; i<256; i++) {
|
||||
buf.put(fgmps_uchar, true);
|
||||
buf.put(i);
|
||||
}
|
||||
buf.put(fgmps_eom, true);
|
||||
dumpmessage(buf.str());
|
||||
|
||||
buf.clr();
|
||||
buf.put(fgmps_som8, true); buf.put(1);
|
||||
|
||||
uval8 = 251; buf.put(fgmps_uchar, true); buf.write1(&uval8);
|
||||
uval16 = 34567; buf.put(fgmps_uint, true); buf.write2(&uval16);
|
||||
uval32 = 1345678901; buf.put(fgmps_ulong, true); buf.write4(&uval32);
|
||||
//uval64 = 9999999999; buf.put(fgmps_ulonglong, true); buf.write8(&uval64);
|
||||
val8 = -120; buf.put(fgmps_char, true); buf.write1(&val8);
|
||||
val16 = -17890; buf.put(fgmps_int, true); buf.write2(&val16);
|
||||
val32 = -1345678901; buf.put(fgmps_long, true); buf.write4(&val32);
|
||||
//val64 = -9999999999; buf.put(fgmps_longlong, true); buf.write8(&val64);
|
||||
valf = 2 * 3.14; buf.put(fgmps_float, true); buf.writef(valf);
|
||||
vald = 3 * 3.1415927; buf.put(fgmps_double, true); buf.writed(vald);
|
||||
vals = "hi there"; buf.put(fgmps_string, true); buf.writes(vals);
|
||||
buf.put(fgmps_eom, true);
|
||||
dumpmessage(buf.str());
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
// message.hxx -- Multiplayer Client/Server message base class
|
||||
//
|
||||
// Written by John Barrett, started November 2003.
|
||||
//
|
||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
|
||||
#include "message.hxx"
|
||||
|
||||
FGMPSInstanceFuncMap FGMPSMessage::funcmap;
|
||||
|
||||
FGMPSMessage::FGMPSMessage()
|
||||
{
|
||||
msgid = 0x0000;
|
||||
elements[0].type = fgmps_null;
|
||||
elements[0].data = NULL;
|
||||
|
||||
}
|
||||
|
||||
string FGMPSMessage::encodemsg()
|
||||
{
|
||||
FGMPSMsgElementEntry* ptr = getelements();
|
||||
|
||||
buf.clr();
|
||||
if (msgid > 255) {
|
||||
buf.put(fgmps_som16, true);
|
||||
buf.write2(&msgid);
|
||||
} else {
|
||||
buf.put(fgmps_som8, true);
|
||||
buf.write1(&msgid);
|
||||
}
|
||||
while (ptr->type != fgmps_null) {
|
||||
buf.put(ptr->type, true);
|
||||
//printf ("adding %02x\n", ptr->type);
|
||||
switch (ptr->type) {
|
||||
case fgmps_uchar:
|
||||
case fgmps_char:
|
||||
buf.write1(ptr->data);
|
||||
break;
|
||||
case fgmps_uint:
|
||||
case fgmps_int:
|
||||
buf.write2(ptr->data);
|
||||
break;
|
||||
case fgmps_ulong:
|
||||
case fgmps_long:
|
||||
buf.write4(ptr->data);
|
||||
break;
|
||||
case fgmps_float:
|
||||
buf.writef(*(float*)ptr->data);
|
||||
break;
|
||||
case fgmps_double:
|
||||
buf.writed(*(double*)ptr->data);
|
||||
break;
|
||||
case fgmps_string:
|
||||
buf.writes(*(string*)ptr->data);
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
|
||||
buf.put(fgmps_eom, true);
|
||||
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
FGMPSMessage* FGMPSMessage::decodemsg(string msg)
|
||||
{
|
||||
FGMPSMessageBuf buf;
|
||||
unsigned char ch;
|
||||
unsigned int mid;
|
||||
FGMPSInstanceFuncMap::iterator fmitr;
|
||||
|
||||
buf.set(msg);
|
||||
buf.ofs(0);
|
||||
ch = buf.get(true);
|
||||
if (ch != fgmps_som8 && ch != fgmps_som16) {
|
||||
throw FGMPSDataException("Invalid start of message");
|
||||
}
|
||||
if (ch == fgmps_som8) {
|
||||
ch = buf.get();
|
||||
mid = ch;
|
||||
} else {
|
||||
mid = *(unsigned int *)buf.read2();
|
||||
}
|
||||
|
||||
fmitr = funcmap.find(mid);
|
||||
if (fmitr == funcmap.end()) {
|
||||
throw FGMPSDataException("MessageID has no registered Message Class");
|
||||
}
|
||||
FGMPSMessage* msgclass = (fmitr->second)();
|
||||
FGMPSMsgElementEntry* elements = msgclass->getelements();
|
||||
while ((ch = buf.get()) != fgmps_eom) {
|
||||
//printf("dump: ");
|
||||
//for (int i=-1; i<16; i++) printf("%02x ", buf.peek(i));
|
||||
//printf("\n");
|
||||
|
||||
if (ch != elements->type) {
|
||||
delete msgclass;
|
||||
throw FGMPSDataException("Decode: Message Structure Error");
|
||||
}
|
||||
switch (ch) {
|
||||
case fgmps_uchar:
|
||||
case fgmps_char:
|
||||
memcpy(elements->data, buf.read1(), 1);
|
||||
break;
|
||||
case fgmps_uint:
|
||||
case fgmps_int:
|
||||
memcpy(elements->data, buf.read2(), 2);
|
||||
break;
|
||||
case fgmps_ulong:
|
||||
case fgmps_long:
|
||||
memcpy(elements->data, buf.read4(), 4);
|
||||
break;
|
||||
case fgmps_float:
|
||||
*(float*)elements->data = buf.readf();
|
||||
break;
|
||||
case fgmps_double:
|
||||
*(double*)elements->data = buf.readd();
|
||||
break;
|
||||
case fgmps_string:
|
||||
ch = buf.get();
|
||||
*(string*)elements->data = buf.reads(ch);
|
||||
break;
|
||||
default:
|
||||
delete msgclass;
|
||||
throw FGMPSDataException("Decode: Unknown data type");
|
||||
break;
|
||||
}
|
||||
elements++;
|
||||
}
|
||||
return msgclass;
|
||||
}
|
||||
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
// message.hxx -- Multiplayer Client/Server message base class
|
||||
//
|
||||
// Written by John Barrett, started November 2003.
|
||||
//
|
||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _FG_MPS_MESSAGE_HXX
|
||||
#define _FG_MPS_MESSAGE_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
#include <stdexcept>
|
||||
#include <map>
|
||||
|
||||
SG_USING_STD(string);
|
||||
SG_USING_STD(invalid_argument);
|
||||
SG_USING_STD(map);
|
||||
|
||||
#include "messagebuf.hxx"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
fgmps_null = 0x00,
|
||||
fgmps_uchar = 0xf0,
|
||||
fgmps_uint = 0xf1,
|
||||
fgmps_ulong = 0xf2,
|
||||
fgmps_ulonglong = 0xf3,
|
||||
fgmps_char = 0xf4,
|
||||
fgmps_int = 0xf5,
|
||||
fgmps_long = 0xf6,
|
||||
fgmps_longlong = 0xf7,
|
||||
fgmps_float = 0xf8,
|
||||
fgmps_double = 0xf9,
|
||||
fgmps_string = 0xfa,
|
||||
fgmps_reserved = 0xfb,
|
||||
fgmps_eom = 0xfc,
|
||||
fgmps_som8 = 0xfd,
|
||||
fgmps_som16 = 0xfe,
|
||||
fgmps_esc = 0xfe
|
||||
} FGMPSMsgElementType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FGMPSMsgElementType type;
|
||||
void * data;
|
||||
} FGMPSMsgElementEntry;
|
||||
|
||||
#define FGMPSMsgElementArrayEnd {fgmps_null, 0}
|
||||
|
||||
class FGMPSMessage;
|
||||
|
||||
typedef FGMPSMessage* FGMPSMessagePtr;
|
||||
typedef FGMPSMessagePtr (*FGMPSMsgInstanceFunc)(void);
|
||||
|
||||
typedef map<unsigned int, FGMPSMsgInstanceFunc> FGMPSInstanceFuncMap;
|
||||
|
||||
class FGMPSMessage
|
||||
{
|
||||
private:
|
||||
static FGMPSInstanceFuncMap funcmap;
|
||||
FGMPSMsgElementEntry elements[1];
|
||||
protected:
|
||||
FGMPSMessageBuf buf;
|
||||
unsigned int msgid;
|
||||
public:
|
||||
static int registermsg(int msgid, FGMPSMsgInstanceFunc func)
|
||||
{
|
||||
funcmap[msgid] = func;
|
||||
}
|
||||
|
||||
FGMPSMessage();
|
||||
~FGMPSMessage() {}
|
||||
|
||||
string encodemsg();
|
||||
static FGMPSMessage* decodemsg(string msg);
|
||||
unsigned int getmessageid() { return msgid; }
|
||||
|
||||
virtual FGMPSMsgElementEntry* getelements() { return elements; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,138 +0,0 @@
|
|||
#include "messagebuf.hxx"
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
unsigned char FGMPSMessageBuf::get(bool raw)
|
||||
{
|
||||
if (pos >= buf.length())
|
||||
throw FGMPSDataException( "FGMPSMessageBuf: Read past end of buffer" );
|
||||
if (raw) return buf[pos++];
|
||||
if ((unsigned char)buf[pos] == 0xff) {
|
||||
pos++;
|
||||
return ((unsigned char)buf[pos++] ^ 0xff);
|
||||
}
|
||||
return buf[pos++];
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::put(unsigned char byte, bool raw)
|
||||
{
|
||||
if (!raw) {
|
||||
if ((byte & 0xf0) == 0xf0) {
|
||||
buf += 0xff;
|
||||
byte = byte ^ 0xff;
|
||||
}
|
||||
}
|
||||
buf += byte;
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::write1(void* data)
|
||||
{
|
||||
put(*(unsigned char *)data);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::write2(void* data)
|
||||
{
|
||||
*((uint16_t*)tmp) = htons(*((uint16_t*)data));
|
||||
put(tmp[0]);
|
||||
put(tmp[1]);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::write4(void* data)
|
||||
{
|
||||
*((uint32_t*)tmp) = htonl(*((uint32_t*)data));
|
||||
put(tmp[0]);
|
||||
put(tmp[1]);
|
||||
put(tmp[2]);
|
||||
put(tmp[3]);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::write8(void* data)
|
||||
{
|
||||
*((uint32_t*)tmp+0) = htonl(*((uint32_t*)data+4));
|
||||
*((uint32_t*)tmp+4) = htonl(*((uint32_t*)data+0));
|
||||
put(tmp[0]);
|
||||
put(tmp[1]);
|
||||
put(tmp[2]);
|
||||
put(tmp[3]);
|
||||
put(tmp[4]);
|
||||
put(tmp[5]);
|
||||
put(tmp[6]);
|
||||
put(tmp[7]);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::writef(float data)
|
||||
{
|
||||
write4(&data);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::writed(double data)
|
||||
{
|
||||
write8(&data);
|
||||
}
|
||||
|
||||
void FGMPSMessageBuf::writes(const string& data)
|
||||
{
|
||||
put(data.length());
|
||||
for (int i=0; i<data.length(); i++) put(data[i]);
|
||||
}
|
||||
|
||||
void* FGMPSMessageBuf::read1()
|
||||
{
|
||||
tmp[0] = get();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void* FGMPSMessageBuf::read2()
|
||||
{
|
||||
tmp[0] = get();
|
||||
tmp[1] = get();
|
||||
*((uint16_t*)tmp) = ntohs(*((uint16_t*)tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void* FGMPSMessageBuf::read4()
|
||||
{
|
||||
tmp[0] = get();
|
||||
tmp[1] = get();
|
||||
tmp[2] = get();
|
||||
tmp[3] = get();
|
||||
*((uint32_t*)tmp) = ntohl(*((uint32_t*)tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void* FGMPSMessageBuf::read8()
|
||||
{
|
||||
unsigned char res[32];
|
||||
|
||||
res[0] = get();
|
||||
res[1] = get();
|
||||
res[2] = get();
|
||||
res[3] = get();
|
||||
res[4] = get();
|
||||
res[5] = get();
|
||||
res[6] = get();
|
||||
res[7] = get();
|
||||
*((uint32_t*)tmp+4) = ntohl(*((uint32_t*)res+0));
|
||||
*((uint32_t*)tmp+0) = ntohl(*((uint32_t*)res+4));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
float FGMPSMessageBuf::readf()
|
||||
{
|
||||
return *((float*)read4());
|
||||
}
|
||||
|
||||
double FGMPSMessageBuf::readd()
|
||||
{
|
||||
return *((double*)read8());
|
||||
}
|
||||
|
||||
string FGMPSMessageBuf::reads(size_t length)
|
||||
{
|
||||
string res = "";
|
||||
for (int i=0; i<length; i++) res += get();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
// messagebuf.hxx -- Multiplayer Client/Server message buffer class
|
||||
//
|
||||
// Written by John Barrett, started November 2003.
|
||||
//
|
||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _FG_MPS_MESSAGEBUF_HXX
|
||||
#define _FG_MPS_MESSAGEBUF_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include STL_STRING
|
||||
#include <stdexcept>
|
||||
|
||||
SG_USING_STD(string);
|
||||
SG_USING_STD(invalid_argument);
|
||||
|
||||
class FGMPSDataException : public invalid_argument
|
||||
{
|
||||
public:
|
||||
FGMPSDataException( const string& what_string )
|
||||
: invalid_argument(what_string) {}
|
||||
};
|
||||
|
||||
class FGMPSMessageBuf
|
||||
{
|
||||
|
||||
private:
|
||||
string buf;
|
||||
size_t pos;
|
||||
unsigned char tmp[16];
|
||||
|
||||
public:
|
||||
|
||||
FGMPSMessageBuf() { init(""); }
|
||||
FGMPSMessageBuf(const string& data) { init(data); }
|
||||
|
||||
~FGMPSMessageBuf() {}
|
||||
|
||||
void init(const string& data)
|
||||
{
|
||||
buf = data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void clr() { buf = ""; }
|
||||
void add(const string& data) { buf += data; }
|
||||
void set(const string& data) { buf = data; }
|
||||
const string& str() { return buf; }
|
||||
size_t ofs() { return pos; }
|
||||
void ofs(size_t val) { pos = val; }
|
||||
|
||||
unsigned char get(bool raw = false);
|
||||
unsigned char peek(size_t ofs = 0) { return buf[pos+ofs]; }
|
||||
void put(unsigned char byte, bool raw = false);
|
||||
|
||||
void write1(void* data);
|
||||
void write2(void* data);
|
||||
void write4(void* data);
|
||||
void write8(void* data);
|
||||
void writef(float data);
|
||||
void writed(double data);
|
||||
void writes(string data);
|
||||
|
||||
void* read1();
|
||||
void* read2();
|
||||
void* read4();
|
||||
void* read8();
|
||||
float readf();
|
||||
double readd();
|
||||
string reads(size_t length);
|
||||
|
||||
const string& buffer() { return buf; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,37 +0,0 @@
|
|||
// message.hxx -- Multiplayer Client/Server message base class
|
||||
//
|
||||
// Written by John Barrett, started November 2003.
|
||||
//
|
||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
|
||||
#include "msg_0001_hello.hxx"
|
||||
|
||||
FGMPSMsg0001Hello::FGMPSMsg0001Hello()
|
||||
{
|
||||
msgid = FGMPSMsg0001HelloID;
|
||||
elements[0].type = fgmps_uint; elements[0].data = &vermajor;
|
||||
elements[1].type = fgmps_uint; elements[1].data = &verminor;
|
||||
elements[2].type = fgmps_uint; elements[2].data = &verpatch;
|
||||
elements[3].type = fgmps_string; elements[3].data = &servname;
|
||||
elements[4].type = fgmps_null; elements[4].data = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// message.hxx -- Multiplayer Client/Server message base class
|
||||
//
|
||||
// Written by John Barrett, started November 2003.
|
||||
//
|
||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _FG_MPS_MSG0001_HXX
|
||||
#define _FG_MPS_MSG0001_HXX
|
||||
|
||||
#include "message.hxx"
|
||||
|
||||
#define FGMPSMsg0001HelloID 0x0001
|
||||
|
||||
class FGMPSMsg0001Hello: public FGMPSMessage
|
||||
{
|
||||
private:
|
||||
FGMPSMsgElementEntry elements[5];
|
||||
public:
|
||||
|
||||
static void registerme()
|
||||
{
|
||||
FGMPSMessage::registermsg(FGMPSMsg0001HelloID, &FGMPSMsg0001Hello::instance);
|
||||
}
|
||||
|
||||
static FGMPSMessage* instance() { return (FGMPSMessage*) new FGMPSMsg0001Hello; }
|
||||
|
||||
virtual FGMPSMsgElementEntry* getelements() { return elements; }
|
||||
|
||||
FGMPSMsg0001Hello();
|
||||
~FGMPSMsg0001Hello() {}
|
||||
|
||||
unsigned int vermajor;
|
||||
unsigned int verminor;
|
||||
unsigned int verpatch;
|
||||
string servname;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,40 +0,0 @@
|
|||
#include "msg_0001_hello.hxx"
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
string str;
|
||||
FGMPSMsg0001Hello msg1, *msg2;
|
||||
|
||||
FGMPSMsg0001Hello::registerme();
|
||||
|
||||
msg1.vermajor = 3;
|
||||
msg1.verminor = 7;
|
||||
msg1.verpatch = 42;
|
||||
msg1.servname = "test";
|
||||
|
||||
str = msg1.encodemsg();
|
||||
|
||||
printf("Message ID = %ui\n", msg1.getmessageid());
|
||||
printf("major = %u\n", msg1.vermajor);
|
||||
printf("minor = %u\n", msg1.verminor);
|
||||
printf("patch = %u\n", msg1.verpatch);
|
||||
printf("sname = %s\n", msg1.servname.c_str());
|
||||
|
||||
printf("dump: ");
|
||||
for (int i=0; i<str.length(); i++) printf("%02x ", (unsigned char)str[i]);
|
||||
printf("\n");
|
||||
|
||||
try {
|
||||
msg2 = (FGMPSMsg0001Hello*)FGMPSMessage::decodemsg(str);
|
||||
} catch (FGMPSDataException e) {
|
||||
printf("Exception: %s\n", e.what());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Message ID = %u\n", msg2->getmessageid());
|
||||
printf("major = %u\n", msg2->vermajor);
|
||||
printf("minor = %u\n", msg2->verminor);
|
||||
printf("patch = %u\n", msg2->verpatch);
|
||||
printf("sname = %s\n", msg2->servname.c_str());
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue