Remove DOS line endings.
This commit is contained in:
parent
89a8e9ccf6
commit
8e72aac9f5
2 changed files with 247 additions and 247 deletions
|
@ -1,149 +1,149 @@
|
||||||
// message.hxx -- Multiplayer Client/Server message base class
|
// message.hxx -- Multiplayer Client/Server message base class
|
||||||
//
|
//
|
||||||
// Written by John Barrett, started November 2003.
|
// Written by John Barrett, started November 2003.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License as
|
// modify it under the terms of the GNU General Public License as
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version.
|
// License, or (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful, but
|
// This program is distributed in the hope that it will be useful, but
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// General Public License for more details.
|
// General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "message.hxx"
|
#include "message.hxx"
|
||||||
|
|
||||||
FGMPSInstanceFuncMap FGMPSMessage::funcmap;
|
FGMPSInstanceFuncMap FGMPSMessage::funcmap;
|
||||||
|
|
||||||
FGMPSMessage::FGMPSMessage()
|
FGMPSMessage::FGMPSMessage()
|
||||||
{
|
{
|
||||||
msgid = 0x0000;
|
msgid = 0x0000;
|
||||||
elements[0].type = fgmps_null;
|
elements[0].type = fgmps_null;
|
||||||
elements[0].data = NULL;
|
elements[0].data = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string FGMPSMessage::encodemsg()
|
string FGMPSMessage::encodemsg()
|
||||||
{
|
{
|
||||||
FGMPSMsgElementEntry* ptr = getelements();
|
FGMPSMsgElementEntry* ptr = getelements();
|
||||||
|
|
||||||
buf.clr();
|
buf.clr();
|
||||||
if (msgid > 255) {
|
if (msgid > 255) {
|
||||||
buf.put(fgmps_som16, true);
|
buf.put(fgmps_som16, true);
|
||||||
buf.write2(&msgid);
|
buf.write2(&msgid);
|
||||||
} else {
|
} else {
|
||||||
buf.put(fgmps_som8, true);
|
buf.put(fgmps_som8, true);
|
||||||
buf.write1(&msgid);
|
buf.write1(&msgid);
|
||||||
}
|
}
|
||||||
while (ptr->type != fgmps_null) {
|
while (ptr->type != fgmps_null) {
|
||||||
buf.put(ptr->type, true);
|
buf.put(ptr->type, true);
|
||||||
//printf ("adding %02x\n", ptr->type);
|
//printf ("adding %02x\n", ptr->type);
|
||||||
switch (ptr->type) {
|
switch (ptr->type) {
|
||||||
case fgmps_uchar:
|
case fgmps_uchar:
|
||||||
case fgmps_char:
|
case fgmps_char:
|
||||||
buf.write1(ptr->data);
|
buf.write1(ptr->data);
|
||||||
break;
|
break;
|
||||||
case fgmps_uint:
|
case fgmps_uint:
|
||||||
case fgmps_int:
|
case fgmps_int:
|
||||||
buf.write2(ptr->data);
|
buf.write2(ptr->data);
|
||||||
break;
|
break;
|
||||||
case fgmps_ulong:
|
case fgmps_ulong:
|
||||||
case fgmps_long:
|
case fgmps_long:
|
||||||
buf.write4(ptr->data);
|
buf.write4(ptr->data);
|
||||||
break;
|
break;
|
||||||
case fgmps_float:
|
case fgmps_float:
|
||||||
buf.writef(*(float*)ptr->data);
|
buf.writef(*(float*)ptr->data);
|
||||||
break;
|
break;
|
||||||
case fgmps_double:
|
case fgmps_double:
|
||||||
buf.writed(*(double*)ptr->data);
|
buf.writed(*(double*)ptr->data);
|
||||||
break;
|
break;
|
||||||
case fgmps_string:
|
case fgmps_string:
|
||||||
buf.writes(*(string*)ptr->data);
|
buf.writes(*(string*)ptr->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.put(fgmps_eom, true);
|
buf.put(fgmps_eom, true);
|
||||||
|
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
FGMPSMessage* FGMPSMessage::decodemsg(string msg)
|
FGMPSMessage* FGMPSMessage::decodemsg(string msg)
|
||||||
{
|
{
|
||||||
FGMPSMessageBuf buf;
|
FGMPSMessageBuf buf;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
unsigned int mid;
|
unsigned int mid;
|
||||||
FGMPSInstanceFuncMap::iterator fmitr;
|
FGMPSInstanceFuncMap::iterator fmitr;
|
||||||
|
|
||||||
buf.set(msg);
|
buf.set(msg);
|
||||||
buf.ofs(0);
|
buf.ofs(0);
|
||||||
ch = buf.get(true);
|
ch = buf.get(true);
|
||||||
if (ch != fgmps_som8 && ch != fgmps_som16) {
|
if (ch != fgmps_som8 && ch != fgmps_som16) {
|
||||||
throw FGMPSDataException("Invalid start of message");
|
throw FGMPSDataException("Invalid start of message");
|
||||||
}
|
}
|
||||||
if (ch == fgmps_som8) {
|
if (ch == fgmps_som8) {
|
||||||
ch = buf.get();
|
ch = buf.get();
|
||||||
mid = ch;
|
mid = ch;
|
||||||
} else {
|
} else {
|
||||||
mid = *(unsigned int *)buf.read2();
|
mid = *(unsigned int *)buf.read2();
|
||||||
}
|
}
|
||||||
|
|
||||||
fmitr = funcmap.find(mid);
|
fmitr = funcmap.find(mid);
|
||||||
if (fmitr == funcmap.end()) {
|
if (fmitr == funcmap.end()) {
|
||||||
throw FGMPSDataException("MessageID has no registered Message Class");
|
throw FGMPSDataException("MessageID has no registered Message Class");
|
||||||
}
|
}
|
||||||
FGMPSMessage* msgclass = (fmitr->second)();
|
FGMPSMessage* msgclass = (fmitr->second)();
|
||||||
FGMPSMsgElementEntry* elements = msgclass->getelements();
|
FGMPSMsgElementEntry* elements = msgclass->getelements();
|
||||||
while ((ch = buf.get()) != fgmps_eom) {
|
while ((ch = buf.get()) != fgmps_eom) {
|
||||||
//printf("dump: ");
|
//printf("dump: ");
|
||||||
//for (int i=-1; i<16; i++) printf("%02x ", buf.peek(i));
|
//for (int i=-1; i<16; i++) printf("%02x ", buf.peek(i));
|
||||||
//printf("\n");
|
//printf("\n");
|
||||||
|
|
||||||
if (ch != elements->type) {
|
if (ch != elements->type) {
|
||||||
delete msgclass;
|
delete msgclass;
|
||||||
throw FGMPSDataException("Decode: Message Structure Error");
|
throw FGMPSDataException("Decode: Message Structure Error");
|
||||||
}
|
}
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case fgmps_uchar:
|
case fgmps_uchar:
|
||||||
case fgmps_char:
|
case fgmps_char:
|
||||||
memcpy(elements->data, buf.read1(), 1);
|
memcpy(elements->data, buf.read1(), 1);
|
||||||
break;
|
break;
|
||||||
case fgmps_uint:
|
case fgmps_uint:
|
||||||
case fgmps_int:
|
case fgmps_int:
|
||||||
memcpy(elements->data, buf.read2(), 2);
|
memcpy(elements->data, buf.read2(), 2);
|
||||||
break;
|
break;
|
||||||
case fgmps_ulong:
|
case fgmps_ulong:
|
||||||
case fgmps_long:
|
case fgmps_long:
|
||||||
memcpy(elements->data, buf.read4(), 4);
|
memcpy(elements->data, buf.read4(), 4);
|
||||||
break;
|
break;
|
||||||
case fgmps_float:
|
case fgmps_float:
|
||||||
*(float*)elements->data = buf.readf();
|
*(float*)elements->data = buf.readf();
|
||||||
break;
|
break;
|
||||||
case fgmps_double:
|
case fgmps_double:
|
||||||
*(double*)elements->data = buf.readd();
|
*(double*)elements->data = buf.readd();
|
||||||
break;
|
break;
|
||||||
case fgmps_string:
|
case fgmps_string:
|
||||||
ch = buf.get();
|
ch = buf.get();
|
||||||
*(string*)elements->data = buf.reads(ch);
|
*(string*)elements->data = buf.reads(ch);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
delete msgclass;
|
delete msgclass;
|
||||||
throw FGMPSDataException("Decode: Unknown data type");
|
throw FGMPSDataException("Decode: Unknown data type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
elements++;
|
elements++;
|
||||||
}
|
}
|
||||||
return msgclass;
|
return msgclass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,98 +1,98 @@
|
||||||
// message.hxx -- Multiplayer Client/Server message base class
|
// message.hxx -- Multiplayer Client/Server message base class
|
||||||
//
|
//
|
||||||
// Written by John Barrett, started November 2003.
|
// Written by John Barrett, started November 2003.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
// Copyright (C) 2003 John R. Barrett - jbarrett@accesshosting.com
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU General Public License as
|
// modify it under the terms of the GNU General Public License as
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version.
|
// License, or (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful, but
|
// This program is distributed in the hope that it will be useful, but
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// General Public License for more details.
|
// General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef _FG_MPS_MESSAGE_HXX
|
#ifndef _FG_MPS_MESSAGE_HXX
|
||||||
#define _FG_MPS_MESSAGE_HXX
|
#define _FG_MPS_MESSAGE_HXX
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
SG_USING_STD(string);
|
SG_USING_STD(string);
|
||||||
SG_USING_STD(invalid_argument);
|
SG_USING_STD(invalid_argument);
|
||||||
SG_USING_STD(map);
|
SG_USING_STD(map);
|
||||||
|
|
||||||
#include "messagebuf.hxx"
|
#include "messagebuf.hxx"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
fgmps_null = 0x00,
|
fgmps_null = 0x00,
|
||||||
fgmps_uchar = 0xf0,
|
fgmps_uchar = 0xf0,
|
||||||
fgmps_uint = 0xf1,
|
fgmps_uint = 0xf1,
|
||||||
fgmps_ulong = 0xf2,
|
fgmps_ulong = 0xf2,
|
||||||
fgmps_ulonglong = 0xf3,
|
fgmps_ulonglong = 0xf3,
|
||||||
fgmps_char = 0xf4,
|
fgmps_char = 0xf4,
|
||||||
fgmps_int = 0xf5,
|
fgmps_int = 0xf5,
|
||||||
fgmps_long = 0xf6,
|
fgmps_long = 0xf6,
|
||||||
fgmps_longlong = 0xf7,
|
fgmps_longlong = 0xf7,
|
||||||
fgmps_float = 0xf8,
|
fgmps_float = 0xf8,
|
||||||
fgmps_double = 0xf9,
|
fgmps_double = 0xf9,
|
||||||
fgmps_string = 0xfa,
|
fgmps_string = 0xfa,
|
||||||
fgmps_reserved = 0xfb,
|
fgmps_reserved = 0xfb,
|
||||||
fgmps_eom = 0xfc,
|
fgmps_eom = 0xfc,
|
||||||
fgmps_som8 = 0xfd,
|
fgmps_som8 = 0xfd,
|
||||||
fgmps_som16 = 0xfe,
|
fgmps_som16 = 0xfe,
|
||||||
fgmps_esc = 0xfe
|
fgmps_esc = 0xfe
|
||||||
} FGMPSMsgElementType;
|
} FGMPSMsgElementType;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
FGMPSMsgElementType type;
|
FGMPSMsgElementType type;
|
||||||
void * data;
|
void * data;
|
||||||
} FGMPSMsgElementEntry;
|
} FGMPSMsgElementEntry;
|
||||||
|
|
||||||
#define FGMPSMsgElementArrayEnd {fgmps_null, 0}
|
#define FGMPSMsgElementArrayEnd {fgmps_null, 0}
|
||||||
|
|
||||||
class FGMPSMessage;
|
class FGMPSMessage;
|
||||||
|
|
||||||
typedef FGMPSMessage* FGMPSMessagePtr;
|
typedef FGMPSMessage* FGMPSMessagePtr;
|
||||||
typedef FGMPSMessagePtr (*FGMPSMsgInstanceFunc)(void);
|
typedef FGMPSMessagePtr (*FGMPSMsgInstanceFunc)(void);
|
||||||
|
|
||||||
typedef map<unsigned int, FGMPSMsgInstanceFunc> FGMPSInstanceFuncMap;
|
typedef map<unsigned int, FGMPSMsgInstanceFunc> FGMPSInstanceFuncMap;
|
||||||
|
|
||||||
class FGMPSMessage
|
class FGMPSMessage
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static FGMPSInstanceFuncMap funcmap;
|
static FGMPSInstanceFuncMap funcmap;
|
||||||
FGMPSMsgElementEntry elements[1];
|
FGMPSMsgElementEntry elements[1];
|
||||||
protected:
|
protected:
|
||||||
FGMPSMessageBuf buf;
|
FGMPSMessageBuf buf;
|
||||||
unsigned int msgid;
|
unsigned int msgid;
|
||||||
public:
|
public:
|
||||||
static int registermsg(int msgid, FGMPSMsgInstanceFunc func)
|
static int registermsg(int msgid, FGMPSMsgInstanceFunc func)
|
||||||
{
|
{
|
||||||
funcmap[msgid] = func;
|
funcmap[msgid] = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGMPSMessage();
|
FGMPSMessage();
|
||||||
~FGMPSMessage() {}
|
~FGMPSMessage() {}
|
||||||
|
|
||||||
string encodemsg();
|
string encodemsg();
|
||||||
static FGMPSMessage* decodemsg(string msg);
|
static FGMPSMessage* decodemsg(string msg);
|
||||||
unsigned int getmessageid() { return msgid; }
|
unsigned int getmessageid() { return msgid; }
|
||||||
|
|
||||||
virtual FGMPSMsgElementEntry* getelements() { return elements; }
|
virtual FGMPSMsgElementEntry* getelements() { return elements; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue