351 lines
8.6 KiB
C
351 lines
8.6 KiB
C
/*
|
|
* PVVMUD a 3D MUD
|
|
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
|
*
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
*/
|
|
#include "pvvmud.H"
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include "msgsrvcli.H"
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgHello
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgHello::CMsgHello():CMessage(MSG_HELLO,sizeof(WORD)){
|
|
setName("MsgHello");
|
|
}
|
|
|
|
CMsgHello::CMsgHello(WORD version):CMessage(MSG_HELLO,sizeof(WORD)){
|
|
setName("MsgHello");
|
|
writeWord(1,version);
|
|
}
|
|
|
|
WORD CMsgHello::getVersion(){
|
|
return readWord(1);
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgLogin
|
|
*
|
|
******************************************************************************/
|
|
|
|
#define MSGLOGINSIZE LOGINNAMELENGTH+LOGINPASSWDLENGTH+sizeof(BYTE)
|
|
|
|
CMsgLogin::CMsgLogin():CMessage(MSG_LOGIN,MSGLOGINSIZE){
|
|
setName("MsgLogin");
|
|
}
|
|
|
|
CMsgLogin::CMsgLogin(char * name, char * passwd, BOOL newUser)
|
|
:CMessage(MSG_LOGIN,MSGLOGINSIZE)
|
|
{
|
|
setName("MsgLogin");
|
|
if ((strlen(name) > LOGINNAMELENGTH) || (strlen(passwd) > LOGINPASSWDLENGTH))
|
|
throw new CException();
|
|
writeString(1,name);
|
|
writeString(1+LOGINNAMELENGTH,passwd);
|
|
writeByte(1+LOGINNAMELENGTH+LOGINPASSWDLENGTH,newUser);
|
|
}
|
|
|
|
char * CMsgLogin::getUserName(){
|
|
return readString(1);
|
|
}
|
|
|
|
char * CMsgLogin::getPasswd(){
|
|
return readString(1+LOGINNAMELENGTH);
|
|
}
|
|
|
|
BOOL CMsgLogin::getNewUser(){
|
|
return readByte(1+LOGINNAMELENGTH+LOGINPASSWDLENGTH);
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgServerInfo
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgServerInfo::CMsgServerInfo()
|
|
:CMessage(MSG_SERVERINFO,2*sizeof(DWORD)+2*sizeof(WORD)){
|
|
|
|
setName("MsgServerInfo");
|
|
}
|
|
|
|
CMsgServerInfo::CMsgServerInfo(CInetAddress & worldSrvAddress,
|
|
CInetAddress & gosAddress)
|
|
:CMessage(MSG_SERVERINFO,2*sizeof(DWORD)+2*sizeof(WORD)){
|
|
|
|
setName("MsgServerInfo");
|
|
writeDWord(1,worldSrvAddress.getAddress());
|
|
writeWord(5,worldSrvAddress.getPort());
|
|
writeDWord(7,gosAddress.getAddress());
|
|
writeWord(11,gosAddress.getPort());
|
|
}
|
|
|
|
CInetAddress * CMsgServerInfo::getWorldSrvAddress(){
|
|
return new CInetAddress(readDWord(1),readWord(5));
|
|
}
|
|
|
|
CInetAddress * CMsgServerInfo::getGOSAddress(){
|
|
return new CInetAddress(readDWord(7),readWord(11));
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgGOSInfo
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgGOSInfo::CMsgGOSInfo()
|
|
:CMessage(MSG_GOSINFO,sizeof(DWORD)+sizeof(WORD)){
|
|
|
|
setName("MsgGOSInfo");
|
|
}
|
|
|
|
CMsgGOSInfo::CMsgGOSInfo(CInetAddress & gosAddress)
|
|
:CMessage(MSG_GOSINFO,sizeof(DWORD)+sizeof(WORD)){
|
|
|
|
setName("MsgGOSInfo");
|
|
writeDWord(1,gosAddress.getAddress());
|
|
writeWord(5,gosAddress.getPort());
|
|
}
|
|
|
|
CInetAddress * CMsgGOSInfo::getGOSAddress(){
|
|
return new CInetAddress(readDWord(1),readWord(5));
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgBye
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgBye::CMsgBye():CMessage(MSG_BYE,sizeof(WORD)){
|
|
setName("MsgBye");
|
|
}
|
|
|
|
CMsgBye::CMsgBye(WORD reason):CMessage(MSG_BYE,sizeof(WORD)){
|
|
setName("MsgBye");
|
|
writeWord(1,reason);
|
|
}
|
|
|
|
WORD CMsgBye::getReason(){
|
|
return readWord(1);
|
|
}
|
|
|
|
char * CMsgBye::getReasonString(WORD reason){
|
|
switch (reason){
|
|
case MSGBYE_QUIT:
|
|
return "Quit";
|
|
case MSGBYE_BADPROTOCOL:
|
|
return "Error in protocol";
|
|
case MSGBYE_UNKNOWN:
|
|
default:
|
|
return "Unkown";
|
|
}
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgGetWorld
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgGetWorld::CMsgGetWorld():CMessage(MSG_GETWORLD,0){
|
|
setName("MsgGetWorld");
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgCommand
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgCommand::CMsgCommand():CMessage(MSG_COMMAND,sizeof(WORD)){
|
|
setName("MsgCommand");
|
|
}
|
|
|
|
CMsgCommand::CMsgCommand(WORD command):CMessage(MSG_COMMAND,sizeof(WORD)){
|
|
setName("MsgCommand");
|
|
writeWord(1,command);
|
|
}
|
|
|
|
WORD CMsgCommand::getCommand(){
|
|
return readWord(1);
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgViewpoint
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgViewpoint::CMsgViewpoint():CMessage(MSG_VIEWPOINT, sizeof(DWORD)*7){
|
|
setName("MsgViewpoint");
|
|
}
|
|
|
|
CMsgViewpoint::CMsgViewpoint(CViewpoint & viewpoint)
|
|
:CMessage(MSG_VIEWPOINT, sizeof(DWORD)*7){
|
|
setName("MsgViewpoint");
|
|
double *position = viewpoint.getPosition().getVector();
|
|
double *direction = viewpoint.getDirection().getVector();
|
|
for (int ii = 0; ii < 3 ; ii++){
|
|
writeDouble(1 + ii*8, position[ii] );
|
|
writeDouble(1 + ii*8+4, direction[ii] );
|
|
}
|
|
writeDWord(25,viewpoint.getTargetId());
|
|
}
|
|
|
|
void CMsgViewpoint::getPosition(CPosition & position){
|
|
double pos[3];
|
|
for (int ii = 0; ii < 3 ; ii++){
|
|
pos[ii] = readDouble(1+ii*8);
|
|
}
|
|
position = CPosition(pos);
|
|
}
|
|
|
|
void CMsgViewpoint::getDirection(CDirection & direction){
|
|
double dir[3];
|
|
for (int ii = 0; ii < 3 ; ii++){
|
|
dir[ii] = readDouble(1+ii*8+4);
|
|
}
|
|
direction = CDirection(dir);
|
|
}
|
|
|
|
DWORD CMsgViewpoint::getTargetId(){
|
|
return readDWord(25);
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgSelection
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgSelection::CMsgSelection():CMessage(MSG_SELECTION,sizeof(WORD)){
|
|
setName("MsgSelection");
|
|
}
|
|
|
|
CMsgSelection::CMsgSelection(WORD objectId):CMessage(MSG_SELECTION,sizeof(WORD)){
|
|
setName("MsgSelection");
|
|
writeWord(1,objectId);
|
|
}
|
|
|
|
WORD CMsgSelection::getObjectId(){
|
|
return readWord(1);
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgAction
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgAction::CMsgAction():CMessage(MSG_ACTION,sizeof(WORD)*2){
|
|
setName("MsgAction");
|
|
}
|
|
|
|
CMsgAction::CMsgAction(WORD objectId, WORD actionId):CMessage(MSG_ACTION,sizeof(WORD)*2){
|
|
setName("MsgAction");
|
|
writeWord(1,objectId);
|
|
writeWord(3,actionId);
|
|
}
|
|
|
|
WORD CMsgAction::getObjectId(){
|
|
return readWord(1);
|
|
}
|
|
|
|
WORD CMsgAction::getActionId(){
|
|
return readWord(3);
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgPlayerInfo
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgPlayerInfo::CMsgPlayerInfo():CMessage(MSG_PLAYERINFO,sizeof(DWORD)){
|
|
setName("MsgPlayerInfo");
|
|
}
|
|
|
|
CMsgPlayerInfo::CMsgPlayerInfo(DWORD masterCellId):CMessage(MSG_PLAYERINFO,sizeof(DWORD)){
|
|
setName("MsgPlayerInfo");
|
|
writeDWord(1,masterCellId);
|
|
}
|
|
|
|
DWORD CMsgPlayerInfo::getMasterCellId(){
|
|
return readDWord(1);
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgPing
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgPing::CMsgPing():CMessage(MSG_PING,sizeof(BYTE)){
|
|
setName("MsgPing");
|
|
}
|
|
|
|
CMsgPing::CMsgPing(BYTE sequenceNumber):CMessage(MSG_PING,sizeof(BYTE)){
|
|
setName("MsgPing");
|
|
writeByte(1,sequenceNumber);
|
|
}
|
|
|
|
BYTE CMsgPing::getSequenceNumber(){
|
|
return readByte(1);
|
|
}
|
|
|
|
/******************************************************************************
|
|
*
|
|
* CMsgPong
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMsgPong::CMsgPong():CMessage(MSG_PONG,sizeof(BYTE)+sizeof(DWORD)){
|
|
setName("MsgPong");
|
|
}
|
|
|
|
CMsgPong::CMsgPong(BYTE sequenceNumber,DWORD serverTime):CMessage(MSG_PONG,sizeof(BYTE)+sizeof(DWORD)){
|
|
setName("MsgPong");
|
|
writeByte(1,sequenceNumber);
|
|
writeDWord(2,serverTime);
|
|
}
|
|
|
|
BYTE CMsgPong::getSequenceNumber(){
|
|
return readByte(1);
|
|
}
|
|
|
|
DWORD CMsgPong::getServerTime(){
|
|
return readDWord(2);
|
|
}
|
|
|