Recovered from microbel

This commit is contained in:
rot
2025-03-05 08:35:31 +01:00
committed by h7x4
commit 88b92402a8
601 changed files with 82177 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libsrvcli.a
libsrvcli_a_SOURCES = action.C bbox.C bsdtree.C communicate.C direction.C exception.C inetaddress.C manager.C message.C messagelist.C msgactionlist.C msgmsg.C msgserver.C msgsrvcli.C msgsrvgos.C msgvarlength.C object.C objectlist.C objectqueue.C position.C socket.C stream.C timekeeper.C viewpoint.C

View File

@@ -0,0 +1,336 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libsrvcli.a
libsrvcli_a_SOURCES = action.C bbox.C bsdtree.C communicate.C direction.C exception.C inetaddress.C manager.C message.C messagelist.C msgactionlist.C msgmsg.C msgserver.C msgsrvcli.C msgsrvgos.C msgvarlength.C object.C objectlist.C objectqueue.C position.C socket.C stream.C timekeeper.C viewpoint.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libsrvcli_a_LIBADD =
libsrvcli_a_OBJECTS = action.o bbox.o bsdtree.o communicate.o \
direction.o exception.o inetaddress.o manager.o message.o messagelist.o \
msgactionlist.o msgmsg.o msgserver.o msgsrvcli.o msgsrvgos.o \
msgvarlength.o object.o objectlist.o objectqueue.o position.o socket.o \
stream.o timekeeper.o viewpoint.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in TODO
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/action.P .deps/bbox.P .deps/bsdtree.P \
.deps/communicate.P .deps/direction.P .deps/exception.P \
.deps/inetaddress.P .deps/manager.P .deps/message.P .deps/messagelist.P \
.deps/msgactionlist.P .deps/msgmsg.P .deps/msgserver.P \
.deps/msgsrvcli.P .deps/msgsrvgos.P .deps/msgvarlength.P .deps/object.P \
.deps/objectlist.P .deps/objectqueue.P .deps/position.P .deps/socket.P \
.deps/stream.P .deps/timekeeper.P .deps/viewpoint.P
SOURCES = $(libsrvcli_a_SOURCES)
OBJECTS = $(libsrvcli_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/srvcli/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libsrvcli.a: $(libsrvcli_a_OBJECTS) $(libsrvcli_a_DEPENDENCIES)
-rm -f libsrvcli.a
$(AR) cru libsrvcli.a $(libsrvcli_a_OBJECTS) $(libsrvcli_a_LIBADD)
$(RANLIB) libsrvcli.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/srvcli
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/srvcli/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

5
common/lib/srvcli/TODO Normal file
View File

@@ -0,0 +1,5 @@
CMessage::writeDouble and readDouble has to be rewriten! Loose every
information less then 0.001

View File

@@ -0,0 +1,52 @@
/*
* 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 "action.H"
CActionList::CActionList():CObjectList(){
currId = 0;
}
CAction * CActionList::getAction(int actionId){
CObjectListItem * item = getFirst();
while (item != NULL){
CAction * action = (CAction*)item->getObject();
if (action->getId() == actionId) return action;
item = item->getNext();
}
return NULL;
}
void CActionList::add(CAction * action){
action->setId(++currId);
CObjectList::addLast(action);
}
CAction::CAction(char * name){
id = 0;
setName(name);
}
void CAction::execute(){
}

68
common/lib/srvcli/bbox.C Normal file
View File

@@ -0,0 +1,68 @@
/*
* 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 "bbox.H"
CBBox::CBBox(){
// p1 and p2 are initialized to (0,0,0)
}
CBBox::CBBox(double x1,double y1, double z1, double x2, double y2, double z2){
p1 = CPosition(MIN(x1,x2),MIN(y1,y2),MIN(z1,z2));
p2 = CPosition(MAX(x1,x2),MAX(y1,y2),MAX(z1,z2));
}
const CPosition & CBBox::getP1() const{
return p1;
}
const CPosition & CBBox::getP2() const{
return p2;
}
void CBBox::initialize(const CPosition & position){
p1 = p2 = position;
}
void CBBox::include(const CPosition & position){
int ii;
for (ii = 0; ii < 3 ; ii++){
if (position.getValue(ii) < p1.getValue(ii))
p1.setValue(ii,position.getValue(ii));
if (position.getValue(ii) > p2.getValue(ii))
p2.setValue(ii,position.getValue(ii));
}
}
int CBBox::inside(const CPosition & position) const{
return ((position >= p1) && (position <= p2));
}
int CBBox::insideXY(const CVector & position) const{
return ((position.getX() >= p1.getX()) && (position.getX() <= p2.getX()) &&
(position.getY() >= p1.getY()) && (position.getY() <= p2.getY()) );
}
ostream& operator<<(ostream&s,const CBBox& b) {
return s << "[ (" << b.getP1() << ") , (" << b.getP2() << ") ]";
}

100
common/lib/srvcli/bsdtree.C Normal file
View File

@@ -0,0 +1,100 @@
/*
* 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 <iostream.h>
#include <stdio.h>
#include "bsdtree.H"
CBSDTreeNode::CBSDTreeNode(double a, double b, double c, double d){
this->a = a;
this->b = b;
this->c = c;
this->d = d;
inNode = NULL;
outNode = NULL;
}
int CBSDTreeNode::inside(double x, double y, double z){
if ( (a*x + b*y + c*z + d ) >= 0.0){
if (inNode != NULL) return inNode->inside(x,y,z);
else return TRUE;
} else {
if (outNode != NULL) return outNode->inside(x,y,z);
else return FALSE;
}
}
CBSDTree::CBSDTree(){
BSDTree = NULL;
}
int CBSDTree::load(char * fileName){
FILE * bsdFile;
if ((bsdFile = fopen(fileName,"r")) == NULL){
cdebug << "Failed to open bsdFile " << fileName << "\n";
return FALSE;
}
BSDTree = loadNode(bsdFile);
fclose(bsdFile);
return TRUE;
}
CBSDTreeNode * CBSDTree::loadNode(FILE * bsdFile){
CBSDTreeNode * node;
char nodeType[256];
double a,b,c,d;
if (fscanf(bsdFile,"%s",nodeType) == 1){
if (strcmp(nodeType,"NODE") == 0){
if (fscanf(bsdFile,"%lf %lf %lf %lf",&a,&b,&c,&d) == 4){
node = new CBSDTreeNode(a,b,c,d);
} else {
cdebug << "File format error in BSDTree file:"
<< " Error in parameters to NODE\n";
return NULL;
}
} else if (strcmp(nodeType,"IN") == 0){
return NULL;
} else if (strcmp(nodeType,"OUT") == 0){
return NULL;
} else {
cdebug << "File format error in BSDTree file: Unknown identifyer\n";
return FALSE;
}
node->setInChild( loadNode(bsdFile) );
node->setOutChild( loadNode(bsdFile) );
return node;
}
return NULL;
}
int CBSDTree::inside(double x, double y, double z){
if (BSDTree != NULL) return BSDTree->inside(x,y,z);
else return FALSE;
}
int CBSDTree::inside(const CPosition & position){
return inside(position.getX(),position.getY(),position.getZ());
}

View File

@@ -0,0 +1,220 @@
/*
* 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 <iostream.h>
#include "communicate.H"
// Debug switches
#define LOGMESSAGES
CBadProtocolException::CBadProtocolException()
:CException("Bad protocol exception"){
}
class CWriteQueueItem: public CObject {
CMessage * m_message;
int m_delete;
public:
CWriteQueueItem(CMessage * message,int del){
m_message = message;
m_delete = del;
}
CMessage * getMessage(){
return m_message;
}
int getDelete(){
return m_delete;
}
};
CCommunicate::CCommunicate(CSocket * socket,CTimeKeeper * timeKeeper){
m_socket = socket;
stream = new CStream(m_socket->getFileDescriptor());
msgWriteQueue = new CObjectQueue();
// Add notification when ready for read or write
m_timeKeeper = timeKeeper;
if (m_timeKeeper != NULL){
m_timeKeeper->addFd(socket->getFileDescriptor(),this,
TIMEKEEPER_IN);
}
currReadMsg = NULL;
currWriteMsg = NULL;
msgList = new CMessageList();
}
CCommunicate::~CCommunicate(){
if (m_timeKeeper != NULL) m_timeKeeper->rmFd(m_socket->getFileDescriptor());
if (stream != NULL) delete stream;
if (m_socket != NULL) delete m_socket;
if (msgList != NULL){
msgList->deleteAll();
delete msgList;
}
}
CSocket * CCommunicate::getSocket(){
return m_socket;
}
void CCommunicate::quit(){
cdebug << "Quit communicate not impl.\n";
}
int CCommunicate::timeKeeperFD(int event){
try {
if (event & TIMEKEEPER_IN) readyToRead();
if (event & TIMEKEEPER_OUT) readyToWrite();
return TRUE;
} catch (CEmptyStreamException * e){
quit();
delete e;
return FALSE;
} catch (CException * e){
cdebug << *e << "\n";
quit();
delete e;
return FALSE;
}
}
void CCommunicate::readyToRead(){
int blocking = TRUE;
do {
if (currReadMsg == NULL){
try {
int id = stream->peepByte();
if ((currReadMsg = msgList->createMsg(id)) == NULL){
cdebug << "Unknown message id : " << id << "\n";
throw new CBadProtocolException();
}
currReadMsg->setManager(getManager());
} catch (CEmptyStreamException * e){
cdebug << *e << "\n";
delete e;
return;
}
}
int result = currReadMsg->recive(stream);
switch (result){
case MESSAGE_OK:
#ifdef LOGMESSAGES
cdebug << "Recive(\""<< getName() << "\"): "
<< currReadMsg->getName() << "\n";
#endif
currReadMsg->executeMsg();
delete currReadMsg;
currReadMsg = NULL;
blocking = FALSE;
break;
case MESSAGE_BLOCKING:
blocking = TRUE;
break;
}
} while (!blocking); // Quit if blocking
}
void CCommunicate::readyToWrite(){
int blocking = TRUE;
do {
// If no message in progres get message from queue
if (currWriteMsg == NULL){
CWriteQueueItem * queueItem = (CWriteQueueItem*)msgWriteQueue->getFIFO();
// Return if queue is empty
if (queueItem == NULL){
timeKeeperSetEvents(TIMEKEEPER_IN);
return;
}
currWriteMsg = queueItem->getMessage();
currWriteMsg->prepareSend();
currWriteDelete = queueItem->getDelete();
delete queueItem;
}
int result = currWriteMsg->send(stream);
switch (result){
case MESSAGE_OK:
#ifdef LOGMESSAGES
cdebug << "Send(\""<< getName() << "\"): "
<< currWriteMsg->getName() << "\n";
#endif
if (currWriteDelete) delete currWriteMsg;
currWriteMsg = NULL;
blocking = FALSE;
break;
case MESSAGE_BLOCKING:
timeKeeperSetEvents(TIMEKEEPER_IN | TIMEKEEPER_OUT);
blocking = TRUE;
break;
}
} while (!blocking); // Quit if blocking
}
void CCommunicate::sendMessage(CMessage * message,int del){
// cdebug << "Add to queue : " << message->getName()
// << " queue size " << msgWriteQueue->getNumItems() << "\n";
// Add message to write queue
msgWriteQueue->add(new CWriteQueueItem(message,del));
// Try to send new message
try {
readyToWrite();
} catch (CException * e){
cdebug << *e << "\n";
quit();
delete e;
}
}
void CCommunicate::setManager(CManager * manager){
this->manager = manager;
}
CManager * CCommunicate::getManager(){
return manager;
}
void CCommunicate::addMsg(MsgCreateFunc_t msgCreateFunc){
msgList->addMsg(msgCreateFunc);
}

View File

@@ -0,0 +1,133 @@
/*
* 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 <math.h>
#include "pvvmud.H"
#include "direction.H"
#define NORMALIZE(index) \
direction[index] -= floor(direction[index]/360.0) * 360.0;
CDirection::CDirection(){
direction[0] = 0;
direction[1] = 0;
direction[2] = 0;
}
CDirection::CDirection(double * direction){
this->direction[0] = direction[0];
this->direction[1] = direction[1];
this->direction[2] = direction[2];
normalize();
}
CDirection::CDirection(double h, double r, double p){
direction[0] = h;
direction[1] = r;
direction[2] = p;
normalize();
}
CDirection& CDirection::operator= (const CDirection& direction) {
this->direction[0] = direction.direction[0];
this->direction[1] = direction.direction[1];
this->direction[2] = direction.direction[2];
return *this;
}
CDirection& CDirection::operator+= (const CDirection& direction) {
this->direction[0] += direction.direction[0];
this->direction[1] += direction.direction[1];
this->direction[2] += direction.direction[2];
normalize();
return *this;
}
CDirection CDirection::operator+ (const CDirection& direction) {
CDirection result;
result.direction[0] = this->direction[0] + direction.direction[0];
result.direction[1] = this->direction[1] + direction.direction[1];
result.direction[2] = this->direction[2] + direction.direction[2];
result.normalize();
return result;
}
CDirection CDirection::operator- () const {
CDirection result;
result.direction[0] = -direction[0];
result.direction[1] = -direction[1];
result.direction[2] = -direction[2];
result.normalize();
return result;
}
CDirection CDirection::operator* (double scale) const {
CDirection result;
result.direction[0] = direction[0]*scale;
result.direction[1] = direction[1]*scale;
result.direction[2] = direction[2]*scale;
result.normalize();
return result;
}
void CDirection::normalize(){
NORMALIZE(0);
NORMALIZE(1);
NORMALIZE(2);
}
double * CDirection::getVector(){
return direction;
}
double CDirection::getValue(int ii) const {
return direction[ii];
}
void CDirection::setValue(int ii,double value) {
direction[ii] += value;
NORMALIZE(ii);
}
double CDirection::rotateHeading(double deltaHeading){
direction[0] += deltaHeading;
NORMALIZE(0);
return direction[0];
}
double CDirection::rotateRoll(double deltaRoll){
direction[1] += deltaRoll;
NORMALIZE(1);
return direction[1];
}
double CDirection::rotatePitch(double deltaPitch){
direction[2] += deltaPitch;
NORMALIZE(2);
return direction[2];
}
ostream& operator<<(ostream&s,const CDirection& d){
return s << "(" << d.getHeading() << "," << d.getRoll()
<< "," << d.getPitch() << ")";
}

View File

@@ -0,0 +1,34 @@
/*
* 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 "exception.H"
CException::CException(){
setName("Unknown exception");
}
CException::CException(char * message){
setName(message);
}
ostream& operator<<(ostream&s,CException& e){
return s << e.getName();
}

View File

@@ -0,0 +1,142 @@
/*
* 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 <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <iostream.h>
#include "inetaddress.H"
#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif
CUnknownHostException::CUnknownHostException()
:CException("Unknown host exception"){
}
CInetAddress::CInetAddress(){
setAddress(INADDR_NONE,0);
}
CInetAddress::CInetAddress(DWORD address){
setAddress(address,0);
}
CInetAddress::CInetAddress(DWORD address,WORD port){
setAddress(address,port);
}
CInetAddress::CInetAddress(char * hostName, WORD port){
struct hostent * hent;
char *portString;
portString=strchr(hostName,':');
if (portString) {
port=atoi(portString+1);
portString[0]=0;
// printf("%s , %s\n",hostName,portString+1);
cdebug << hostName << " , " << (portString+1) << "\n";
};
if (hostName) {
if (!strcmp("localhost",hostName)) {
// printf("Connecting to localhost, port : %i",port);
cdebug << "Connecting to localhost, port : " << port << "\n";
if (portString) portString[0]=':';
setAddress(INADDR_LOOPBACK,port);
return;
}
}
if ((hent = gethostbyname(hostName)) == NULL){
throw new CUnknownHostException();
}
if (portString) {
portString[0]=':';
}
//printf("Connecting to another server, port : %i",port);
cdebug << "Connecting to another server, port : " << port << "\n";
setAddress(htonl(*((DWORD*)hent->h_addr)),port);
}
CInetAddress::CInetAddress(char * hostName){
struct hostent * hent;
char *portString;
WORD port=0;
portString=strchr(hostName,':');
if (portString) {
port=atoi(portString+1);
};
if ((hent = gethostbyname(hostName)) == NULL){
throw new CUnknownHostException();
}
setAddress(htonl(*((DWORD*)hent->h_addr)),port);
}
void CInetAddress::setAddress(DWORD address,WORD port){
m_address = address;
m_port = port;
}
char * CInetAddress::getHostName(){
struct hostent * hent;
DWORD address;
address=htonl(m_address);
if ((hent = gethostbyaddr((char*)&address, sizeof m_address, AF_INET)) == NULL){
throw new CUnknownHostException();
}
return hent->h_name;
}
char * CInetAddress::getAddressString(){
static char addr[1024];
try {
sprintf(addr,"%s:%d",getHostName(),getPort());
} catch (CException * e){
cdebug << *e << "\n";
delete e;
DWORD naddr = htonl(getAddress());
struct in_addr * inaddr = (struct in_addr*)&naddr;
sprintf(addr,"%s:%d",inet_ntoa(*inaddr),getPort());
}
return addr;
}
ostream& operator<<(ostream&s,const CInetAddress& address){
return s << ((CInetAddress)address).getAddressString();
}

View File

@@ -0,0 +1,41 @@
/*
* 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 <iostream.h>
#include "manager.H"
#include "communicate.H"
CManager::CManager(){
m_communicate = NULL;
}
CManager::CManager(CCommunicate * communicate){
setCommunicate(communicate);
}
CManager::~CManager(){
if (m_communicate != NULL) delete m_communicate;
}
void CManager::setCommunicate(CCommunicate * communicate){
m_communicate = communicate;
communicate->setManager(this);
}

234
common/lib/srvcli/message.C Normal file
View File

@@ -0,0 +1,234 @@
/*
* 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 <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include "message.H"
#define WORD_MS_BYTE(w) (BYTE)( w >> 8 )
#define WORD_LS_BYTE(w) (BYTE)( w & 0xFF )
#define DWORD_MS_WORD(w) (WORD)( w >> 16 )
#define DWORD_LS_WORD(w) (WORD)( w & 0xFFFF )
#define WORD_FROM_BYTE(ms,ls) (WORD)( (WORD)ms << 8 | (WORD)ls)
#define DWORD_FROM_WORD(ms,ls) (DWORD)( (DWORD)ms << 16 | (DWORD)ls)
/******************************************************************************
*
* CMessage
*
******************************************************************************/
CMessage::CMessage(BYTE id, long length){
this->length = length+1;
message = (BYTE*)malloc(this->length);
msglength = this->length;
writeByte(0,id);
writeIndex = 0;
readIndex = 0;
}
CMessage::~CMessage(){
if (message != NULL) free(message);
}
void CMessage::reallocMessage(long size){
message = (BYTE*)realloc(message,length+size);
msglength = length+size;
}
BYTE CMessage::getId(){
return readByte(0);
}
long CMessage::getLength(){
return length;
}
CMessage * CMessage::createMsg(){
return (CMessage*)NULL;
}
int CMessage::reciveHead(CStream * stream){
return FALSE;
}
int CMessage::send(CStream * stream){
if (readIndex >= length){
return MESSAGE_OK;
}
long num = stream->writeBuf(&message[readIndex],length-readIndex);
if (num == -1) return MESSAGE_BLOCKING;
readIndex += num;
if (readIndex == length) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::recive(CStream * stream){
if (writeIndex >= length){
return MESSAGE_OK;
}
long num = stream->readBuf(&message[writeIndex],length-writeIndex);
if (num == -1) return MESSAGE_BLOCKING;
writeIndex += num;
if (writeIndex == length) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::reciveMessage(CStream * stream,long index,long size){
long num = stream->readBuf(&message[index],size);
if (num == -1) return MESSAGE_BLOCKING;
writeIndex += num;
if (num == size) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
int CMessage::sendMessage(CStream * stream,long index,long size){
long num = stream->writeBuf(&message[index],size);
if (num == -1) return MESSAGE_BLOCKING;
readIndex += num;
if (num == size) return MESSAGE_OK;
return MESSAGE_BLOCKING;
}
long CMessage::getWriteIndex(){
return writeIndex;
}
long CMessage::getReadIndex(){
return readIndex;
}
void CMessage::writeByte(long index,BYTE byte){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) throw new CException("Message write index out of range exception");
message[index] = byte;
currpos = index + 1;
}
void CMessage::writeWord(long index,WORD word){
writeByte(index,WORD_MS_BYTE(word));
writeByte(index+1,WORD_LS_BYTE(word));
}
void CMessage::writeDWord(long index,DWORD dword){
writeWord(index,DWORD_MS_WORD(dword));
writeWord(index+2,DWORD_LS_WORD(dword));
}
void CMessage::writeDouble(long index,double value){
long longval = (long)(value*1000.0);
writeDWord(index,(DWORD)longval);
}
void CMessage::writeBuf(long index,BYTE * buf,long size){
long ii;
for (ii = 0; ii < size; ii++){
writeByte(index+ii,buf[ii]);
}
}
void CMessage::writeString(long index,char * str){
writeBuf(index,(BYTE*)str,strlen(str)+1);
}
void CMessage::writePosition(long index,const CPosition& position){
for (long ii = 0; ii < 3; ii++){
writeDouble(index+ii*4,position.getValue(ii));
}
}
void CMessage::writeDirection(long index,const CDirection& direction){
for (long ii = 0; ii < 3; ii++){
writeDouble(index+ii*4,direction.getValue(ii));
}
}
BYTE CMessage::readByte(long index){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) {
char msg[1024];
sprintf(msg,"Message read index %li out of range %li exception"
,index,msglength);
throw new CException(msg);
}
currpos = index + 1;
return message[index];
}
WORD CMessage::readWord(long index){
return WORD_FROM_BYTE(readByte(index),readByte(index+1));
}
DWORD CMessage::readDWord(long index){
return DWORD_FROM_WORD(readWord(index),readWord(index+2));
}
double CMessage::readDouble(long index){
long longval;
longval = (long)DWORD_FROM_WORD(readWord(index),readWord(index+2));
return (double)longval / 1000.0;
}
void CMessage::readBuf(long index,BYTE * buf,long size){
long ii;
if (buf == NULL) throw new CException("Message buffer null exception");
for (ii = 0; ii < size; ii++){
buf[ii] = readByte(index+ii);
}
}
char * CMessage::readString(long index){
if (index < 0) index = currpos;
if ((index > msglength) || (index < 0) || (message == NULL)) throw new CException("Message readString index out of range exception");
long ii,size=0;
char * str;
// Find string size
while (((index+size) < msglength) && (readByte(index+size++) != '\0'));
// Malloc and copy string
str = (char*)malloc(size);
if (str == NULL) throw new CException("Out of memory exception");
for (ii = 0; ii < size; ii++) str[ii] = readByte(index+ii);
return str;
}
CPosition CMessage::readPosition(long index){
CPosition position;
for (long ii = 0; ii < 3; ii++){
position.setValue(ii,readDouble(index+ii*4));
}
return position;
}
CDirection CMessage::readDirection(long index){
CDirection direction;
for (long ii = 0; ii < 3; ii++){
direction.setValue(ii,readDouble(index+ii*4));
}
return direction;
}

View File

@@ -0,0 +1,64 @@
/*
* 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 <iostream.h>
#include "messagelist.H"
CMessageItem::CMessageItem(BYTE id, int length, MsgCreateFunc_t msgCreateFunc){
this->id = id;
this->length = length;
this->msgCreateFunc = msgCreateFunc;
}
CMessageItem * CMessageList::getItem(BYTE id){
CObjectListItem * curr;
CMessageItem * msgItem;
curr = getFirst();
while (curr != NULL){
msgItem = (CMessageItem*)curr->getObject();
if (msgItem->id == id) return msgItem;
curr = curr->getNext();
}
return NULL;
}
void CMessageList::addMsg(MsgCreateFunc_t msgCreateFunc){
CMessage * msg = msgCreateFunc();
// cdebug << "Msg: id " << (int)msg->getId() << " length "
// << msg->getLength() << "\n";
addLast( new CMessageItem(msg->getId(),msg->getLength(),msgCreateFunc));
delete msg;
}
int CMessageList::getLength(BYTE id){
CMessageItem * msgItem;
msgItem = getItem(id);
if (msgItem != NULL) return msgItem->length;
return -1;
}
CMessage * CMessageList::createMsg(BYTE id){
CMessageItem * msgItem;
msgItem = getItem(id);
if (msgItem != NULL) return msgItem->msgCreateFunc();
return NULL;
}

67
common/lib/srvcli/mkmsgvar.pl Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/perl
foreach $name (@ARGV) {
$ucname = ucfirst $name;
$classname = "C$ucname";
$filename = lc $name;
$NAME = uc $name;
print "Creating H file $filename.H for class $classname\n";
open(file, "> ../../include/$filename.H") or die "Can't open $filename.H\n";
print file "#ifndef _", $NAME,"_H\n";
print file "#define _", $NAME,"_H\n";
print file "\n";
print file "#include \"msgvarlength.H\"\n";
print file "\n";
print file "class $classname : public CMsgVarLength \{\n";
print file "\n";
print file " arg\n";
print file "\n";
print file "public:\n";
print file " $classname();\n";
print file " $classname( arg );\n";
print file " ~$classname();\n";
print file " virtual void send(CStream * stream);\n";
print file " virtual void recive(CStream * stream);\n";
print file " getArg() { return arg; }\n";
print file "}\;\n";
print file "\n";
print file "#endif // _",$NAME,"_H\n";
close(file);
print "Creating C file $filename.C for class $classname\n";
open(file, "> $filename.C") or die "Can't open $filename.C\n";
print file "#include \"pvvmud.H\"\n";
print file "#include \"$filename.H\"\n";
print file "\n";
print file "$classname","::","$classname","():CMsgVarLength('?'){\n";
print file "\n";
print file "}\n";
print file "\n";
print file "$classname","::","$classname","( arg ):CMsgVarLength('?'){\n";
print file " setBodyLength( ? );\n";
print file "}\n";
print file "\n";
print file "$classname","::~","$classname","(){\n";
print file "\n";
print file "}\n";
print file "\n";
print file "void $classname","::recive(CStream * stream){\n";
print file "}\n";
print file "\n";
print file "void $classname","::send(CStream * stream){\n";
print file " CMsgVarLength::send(stream);\n";
print file "}\n";
print file "\n";
close(file);
}

View File

@@ -0,0 +1,68 @@
/*
* 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 "msgactionlist.H"
CMsgActionList::CMsgActionList():CMsgVarLength(MSG_ACTIONLIST){
setName("MsgActionList");
setBodyLength( sizeof(WORD)*2 );
writeWord(getLength(),0); // ObjectId
setNumActions(0); // NumActions
}
CMsgActionList::CMsgActionList(WORD objectId):CMsgVarLength(MSG_ACTIONLIST){
setName("MsgActionList");
setBodyLength( sizeof(WORD)*2 );
writeWord(getLength(),objectId);
setNumActions(0); // NumActions
}
void CMsgActionList::setNumActions(int num){
writeWord(getLength()+2,num);
}
int CMsgActionList::getNumActions(){
return readWord(getLength()+2);
}
CObjectList* CMsgActionList::getActionList(){
CObjectList * actionList = new CObjectList();
WORD numActions = getNumActions();
while (numActions--){
int id = readWord(MSGCURRPOS);
CAction * action = new CAction(readString(MSGCURRPOS));
action->setId(id);
actionList->addLast( (CObject*)action );
}
return actionList;
}
void CMsgActionList::addAction(CAction * action){
int endpos = getBodyLength();
setBodyLength(endpos + sizeof(WORD) + strlen(action->getName())+1);
endpos += getLength();
writeWord(endpos,action->getId()); endpos +=2;
writeString(endpos,action->getName());
setNumActions(getNumActions()+1);
}
WORD CMsgActionList::getObjectId(){
return readWord(getLength());
}

View File

@@ -0,0 +1,46 @@
/*
* 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 <string.h>
#include "msgmsg.H"
CMsgMsg::CMsgMsg():CMsgVarLength(MSG_MSG){
setName("MsgMsg");
}
CMsgMsg::CMsgMsg( const char * msg ):CMsgVarLength(MSG_MSG){
setName("MsgMsg");
setBodyLength( strlen(msg) );
writeBuf(getLength(),(BYTE*)msg,strlen(msg));
}
CMsgMsg::~CMsgMsg(){
}
int CMsgMsg::getMsgLength(){
return getBodyLength() + 1;
}
void CMsgMsg::getMsg(char * msg){
readBuf(getLength(),(BYTE*)msg,getBodyLength());
msg[getBodyLength()] = '\0';
}

View File

@@ -0,0 +1,36 @@
/*
* 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 "msgserver.H"
CMsgServerLogin::CMsgServerLogin():CMessage(MSG_SERVERLOGIN,sizeof(DWORD)+sizeof(WORD)){
setName("ServerLogin");
}
CMsgServerLogin::CMsgServerLogin(CInetAddress & serverAddress):CMessage(MSG_SERVERLOGIN,sizeof(DWORD)+sizeof(WORD)){
setName("ServerLogin");
writeDWord(1,serverAddress.getAddress());
writeWord(5,serverAddress.getPort());
}
CInetAddress * CMsgServerLogin::getAddress(){
return new CInetAddress(readDWord(1),readWord(5));
}

View File

@@ -0,0 +1,350 @@
/*
* 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);
}

View File

@@ -0,0 +1,23 @@
/*
* 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 "msgsrvgos.H"

View File

@@ -0,0 +1,65 @@
/*
* 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 "msgvarlength.H"
CMsgVarLength::CMsgVarLength(BYTE id):CMessage(id,sizeof(DWORD)){
writeDWord(1,0);
}
long CMsgVarLength::getBodyLength(){
DWORD bodyLength = readDWord(1);
reallocMessage(bodyLength);
return (long)bodyLength;
}
void CMsgVarLength::setBodyLength(DWORD bodyLength){
reallocMessage(bodyLength);
writeDWord(1,bodyLength);
}
int CMsgVarLength::sendBody(CStream * stream){
long length = getBodyLength()-(getReadIndex()-getLength());
if (length == 0) return MESSAGE_OK;
return sendMessage(stream,getReadIndex(),length);
}
int CMsgVarLength::reciveBody(CStream * stream){
long length = getBodyLength()-(getWriteIndex()-getLength());
if (length == 0) return MESSAGE_OK;
return reciveMessage(stream,getWriteIndex(),length);
}
int CMsgVarLength::recive(CStream * stream){
if ( (CMessage::recive(stream)==MESSAGE_OK) &&
(reciveBody(stream)==MESSAGE_OK) ){
return MESSAGE_OK;
}
return MESSAGE_BLOCKING;
}
int CMsgVarLength::send(CStream * stream){
if ( (CMessage::send(stream)==MESSAGE_OK) &&
(sendBody(stream)==MESSAGE_OK) ){
return MESSAGE_OK;
}
return MESSAGE_BLOCKING;
}

View File

@@ -0,0 +1,39 @@
/*
* 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 <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "pvvmud.H"
#include "object.H"
CObject::CObject(){
m_name = NULL;
}
CObject::~CObject(){
if (m_name != NULL) free(m_name);
}
void CObject::setName(char * name){
int length = strlen(name);
if (m_name != NULL) free(m_name);
m_name = (char*)malloc(length+1);
strcpy(m_name,name);
}

View File

@@ -0,0 +1,204 @@
/*
* 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 <stdio.h>
#include "pvvmud.H"
#include "objectlist.H"
CObjectListItem::CObjectListItem(){
m_next = NULL;
m_prev = NULL;
m_object = NULL;
}
CObjectListItem::CObjectListItem(CObject * object){
m_next = NULL;
m_prev = NULL;
m_object = object;
}
void CObjectListItem::setObject(CObject * object){
m_object = object;
}
CObject * CObjectListItem::getObject(){
return m_object;
}
void CObjectListItem::setNext(CObjectListItem * next){
m_next = next;
}
CObjectListItem * CObjectListItem::getNext(){
return m_next;
}
void CObjectListItem::setPrev(CObjectListItem * prev){
m_prev = prev;
}
CObjectListItem * CObjectListItem::getPrev(){
return m_prev;
}
CObjectList::CObjectList(){
m_first = NULL;
m_last = NULL;
}
CObjectList::~CObjectList(){
deleteList();
}
void CObjectList::deleteList(){
CObjectListItem *item;
while ((item = removeFirst()) != NULL){
delete item;
}
}
void CObjectList::deleteAll(){
CObjectListItem *item;
while ((item = removeFirst()) != NULL){
CObject * object = item->getObject();
delete object;
delete item;
}
}
CObjectListItem * CObjectList::addFirst(CObject * obj){
CObjectListItem * item = new CObjectListItem(obj);
if (m_first != NULL){
item->setNext(m_first);
m_first->setPrev(item);
m_first = item;
} else {
m_first = m_last = item;
}
return item;
}
CObjectListItem * CObjectList::addLast(CObject * obj){
CObjectListItem * item = new CObjectListItem(obj);
if (m_last != NULL){
m_last->setNext(item);
item->setPrev(m_last);
m_last = item;
} else {
m_first = m_last = item;
}
return item;
}
CObjectListItem * CObjectList::removeFirst(){
if (m_first == NULL) return NULL;
CObjectListItem *item = m_first;
m_first = m_first->getNext();
if (m_first != NULL){
m_first->setPrev(NULL);
} else {
m_last = NULL;
}
if (item != NULL){
item->setNext(NULL);
item->setPrev(NULL);
}
return item;
}
CObjectListItem * CObjectList::removeLast(){
if (m_last == NULL) return NULL;
CObjectListItem *item = m_last;
m_last = m_last->getPrev();
if (m_last != NULL){
m_last->setNext(NULL);
} else {
m_first = NULL;
}
if (item != NULL){
item->setNext(NULL);
item->setPrev(NULL);
}
return item;
}
void CObjectList::remove(CObject * obj){
CObjectListItem *curr,*next,*prev;
curr = m_first;
prev = NULL;
while (curr != NULL){
next = curr->getNext();
if ( obj == curr->getObject()){
if (prev != NULL){
prev->setNext(next);
} else {
m_first = next;
}
if (next != NULL){
next->setPrev(prev);
} else {
m_last = prev;
}
delete curr;
return;
}
prev = curr;
curr = next;
}
}
CObjectListItem * CObjectList::getFirst(){
return m_first;
}
CObjectListItem * CObjectList::getLast(){
return m_last;
}
//CObjectListItem * CObjectList::getNext(CObjectListItem * objListItem){
// return objListItem->getNext();
//}
CObjectListItem * CObjectList::getItem(int index) {
int i=0;
CObjectListItem * item = getFirst();
while(item!=NULL && i<index) {
item = item->getNext();
i++;
}
if (i==index) return item;
else return NULL;
}
int CObjectList::getNumItems(){
CObjectListItem * item = getFirst();
int numItems = 0;
while (item != NULL){
item = item->getNext();
numItems++;
}
return numItems;
}

View File

@@ -0,0 +1,49 @@
/*
* 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 "objectqueue.H"
CObjectQueue::CObjectQueue():CObjectList(){
}
CObjectQueue::~CObjectQueue(){
}
void CObjectQueue::add(CObject * object){
addFirst(object);
}
CObject * CObjectQueue::getFIFO(){
CObjectListItem * item = removeLast();
if (item == NULL) return NULL;
CObject * object = item->getObject();
delete item;
return object;
}
CObject * CObjectQueue::getStack(){
CObjectListItem * item = removeFirst();
if (item == NULL) return NULL;
CObject * object = item->getObject();
delete item;
return object;
}

View File

@@ -0,0 +1,107 @@
/*
* 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 "position.H"
CPosition::CPosition(){
position[0] = 0;
position[1] = 0;
position[2] = 0;
}
CPosition::CPosition(double * position){
this->position[0] = position[0];
this->position[1] = position[1];
this->position[2] = position[2];
}
CPosition::CPosition(double x, double y, double z){
position[0] = x;
position[1] = y;
position[2] = z;
}
CPosition::~CPosition(){
}
CPosition& CPosition::operator= (const CPosition& position) {
this->position[0] = position.position[0];
this->position[1] = position.position[1];
this->position[2] = position.position[2];
return *this;
}
CPosition& CPosition::operator+= (const CPosition& position) {
this->position[0] += position.position[0];
this->position[1] += position.position[1];
this->position[2] += position.position[2];
return *this;
}
int CPosition::operator< (const CPosition& position) const {
return ((this->position[0] < position.position[0])&&
(this->position[1] < position.position[1])&&
(this->position[2] < position.position[2]));
}
int CPosition::operator> (const CPosition& position) const {
return ((this->position[0] > position.position[0])&&
(this->position[1] > position.position[1])&&
(this->position[2] > position.position[2]));
}
int CPosition::operator<= (const CPosition& position) const {
return ((this->position[0] <= position.position[0])&&
(this->position[1] <= position.position[1])&&
(this->position[2] <= position.position[2]));
}
int CPosition::operator>= (const CPosition& position) const {
return ((this->position[0] >= position.position[0])&&
(this->position[1] >= position.position[1])&&
(this->position[2] >= position.position[2]));
}
double * CPosition::getVector(){
return position;
}
CPosition CPosition::operator- (const CPosition& position) const{
CPosition result;
result.position[0] = this->position[0] - position.position[0];
result.position[1] = this->position[1] - position.position[1];
result.position[2] = this->position[2] - position.position[2];
return result;
}
CPosition CPosition::operator- () const{
CPosition result;
result.position[0] = - position[0];
result.position[1] = - position[1];
result.position[2] = - position[2];
return result;
}
ostream& operator<<(ostream&s,const CPosition& p){
return s << "(" << p.getX() << "," << p.getY() << "," << p.getZ() << ")";
}

195
common/lib/srvcli/socket.C Normal file
View File

@@ -0,0 +1,195 @@
/*
* 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 <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "socket.H"
#include "manager.H"
#include <sys/utsname.h>
// TODO:
// address and localAddress are not set systematically
//
CSocketException::CSocketException():CException("Socket exception"){
}
CSocket::CSocket(){
if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
throw new CSocketException();
}
}
#ifndef socklen_t
#define socklen_t int
#endif
CSocket::CSocket(int fd){
struct sockaddr_in sin;
socklen_t addrlen = sizeof(sin);
this->fd = fd;
addrlen = sizeof(sin);
getpeername(fd,(struct sockaddr*)&sin,&addrlen);
address = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
addrlen = sizeof(sin);
getsockname(fd,(struct sockaddr*)&sin,&addrlen);
localAddress = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
void CSocket::bind( char *addr, int port ) {
int opt = 1; /* For setting reuse_addr */
struct sockaddr_in sin; /* Address for socket */
struct linger ld; /* To set linger option */
localPort = port;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt) );
ld.l_onoff = 0;
ld.l_linger = 0;
setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&ld, sizeof(ld));
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = htonl(INADDR_ANY);
// Try to bind the address to the socket.
if(::bind(fd, (struct sockaddr*)&sin, sizeof(sin)) < 0) {
throw new CSocketException();
}
socklen_t length = sizeof(sin);
getsockname(fd, (struct sockaddr*)&sin, &length);
if (strcmp(addr,"any")) {
if (!strcmp(addr,"localhost")) {
struct hostent *hptr;
struct utsname myname;
if (uname(&myname)<0) return;
if ((hptr=gethostbyname(myname.nodename))==NULL) return;
sin.sin_addr.s_addr = (*((DWORD*)hptr->h_addr_list[0]));
} else {
CInetAddress address(addr);
sin.sin_addr.s_addr = address.getAddress();
}
}
localAddress.setAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
void CSocket::listen(int number){
if (::listen(fd,number) < 0)
throw new CSocketException();
}
void CSocket::connect(unsigned long addr, int port){
struct sockaddr_in sin;
// address = CInetAddress(addr,port);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = htonl(addr);
if (::connect(fd, (struct sockaddr*)&sin, sizeof sin ) == -1) {
cdebug << "ERROR: Connect: " << strerror(errno) << "\n";
throw new CSocketException();
}
socklen_t length = sizeof(sin);
getpeername(fd,(struct sockaddr*)&sin,&length);
address = CInetAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
length = sizeof(sin);
getsockname(fd, (struct sockaddr*)&sin, &length);
localAddress.setAddress(ntohl(sin.sin_addr.s_addr),ntohs(sin.sin_port));
}
CStream * CSocket::getStream(){
return new CStream(fd);
}
void CSocket::close(){
::close(fd);
}
CClientSocket::CClientSocket(unsigned long addr, int port):CSocket(){
connect(addr,port);
}
CServerSocket::CServerSocket(int port):CSocket(){
bind("any",port);
listen(5);
}
CServerSocket::CServerSocket(char *addr, int port):CSocket(){
bind(addr,port);
listen(5);
}
CSocket * CServerSocket::accept(){
int n_sock; /* For accepting connection */
struct sockaddr_in sin; /* Address for socket */
socklen_t len; /* For use with accept() */
len = sizeof(sin);
if ((n_sock=::accept(getFileDescriptor(), (struct sockaddr*)&sin, &len)) < 0){
cdebug << "CServerSocket::accept Error: " << strerror(errno) << "\n";
throw new CSocketException();
} else {
return new CSocket(n_sock);
}
}
void CSocket::set_fl(int flags) /* flags are file status flags to turn o
n */
{
int val;
if ((val = fcntl(fd, F_GETFL, 0)) < 0)
perror("Error Socket: fcntl");
val |= flags;
if (fcntl(fd, F_SETFL, val) < 0)
perror("Error Socket: fcntl");
}
void CSocket::setNonBlocking(){
set_fl(O_NONBLOCK);
}

189
common/lib/srvcli/stream.C Normal file
View File

@@ -0,0 +1,189 @@
/*
* 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 <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "stream.H"
#define INC_START if (++start >= STREAMSIZE) start = 0; size--
#define INC_STOP if (++stop >= STREAMSIZE) stop = 0; size++
/////////////////////////////////////////////////////////////////////////////
// Stream exceptions
CEmptyStreamException::CEmptyStreamException()
:CException("Empty stream exception"){
}
CEOFException::CEOFException():CException("EOF exception"){
}
CIOException::CIOException():CException("IO exception"){
}
/////////////////////////////////////////////////////////////////////////////
// Constructor and destructor
CStream::CStream(int fd){
start = stop = size = 0;
this->fd = fd;
}
CStream::~CStream(){
close(fd);
}
/////////////////////////////////////////////////////////////////////////////
// Private functions
/////////////////////////////////////////////////////////////////////////////
int CStream::writeInBuf(char * msg, int length){
int nn = 0;
if ((STREAMSIZE - size) < length) return FALSE;
while (nn < length){
buf[stop] = msg[nn++];
INC_STOP;
}
return TRUE;
}
unsigned long totalread = 0;
unsigned long totalwrite = 0;
int CStream::fillBuf(){
long length,max;
char rbuf[STREAMSIZE];
max = MIN(STREAMSIZE-size,READBUFSIZE);
#ifndef CRYPTO
length=::read(fd,&rbuf,max);
if (length > 0) {
totalread+=length;
writeInBuf(rbuf,length);
};
#else
length=CCrypto::read(fd,&m_rbuf,(STREAMSIZE-size));
if (length > 0) {
totalread+=length;
writeInBuf(m_rbuf,length);
};
#endif
// Check for errors
if ((max != 0) && (length == 0)){
throw new CEOFException();
} else if (length == -1){
switch(errno){
case EAGAIN: // Non-blocking I/O
break;
default:
cdebug << "Error reading socket: " << strerror(errno) << "\n";
throw new CIOException();
break;
}
}
return size;
}
/////////////////////////////////////////////////////////////////////////////
// Public functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// peepByte
//
// Description: Returning first byte in input stream without removing it from
// input buf.
//
// Return : First byte in input stream
//
// Exceptions : CEmptyStreamException, CEOFException, CIOException
//
BYTE CStream::peepByte(){
fillBuf();
if (size < 1) throw new CEmptyStreamException();
return buf[start];
}
/////////////////////////////////////////////////////////////////////////////
// readBuf
//
// Description: Read length bytes from stream
//
// Return : Number of bytes read or -1 if read would have blocked
//
// Exceptions : CEOFException , CIOException
//
int CStream::readBuf(BYTE * msg, int length){
if (fillBuf() == 0) return -1;
int nn = 0;
while ((size >= 1) && (nn < length)){
msg[nn++] = buf[start];
INC_START;
if (size == 0) fillBuf();
}
return nn;
}
/////////////////////////////////////////////////////////////////////////////
// writeBuf
//
// Description: Write length bytes to stream
//
// Return : Number of bytes writen or -1 if write would have blocked
//
// Exceptions : CEOFException , CIOException
//
int CStream::writeBuf(BYTE * buf,int length){
#ifdef CRYPTO
int num = CCrypto::write(fd,buf,length);
#else
int num = ::write(fd,buf,length);
#endif
if (num >= 0){
totalwrite += num;
} else {
if (num == -2) return -1; // Error handling in crypto-routines
switch (errno){
case EPIPE:
throw new CEOFException();
break;
case EAGAIN: // Non-Blocking I/O
return -1;
break;
default:
throw new CIOException();
break;
}
}
return num;
}

View File

@@ -0,0 +1,258 @@
/*
* 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 <string.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/types.h>
#include <iostream.h>
#include "timekeeper.H"
#include "exception.H"
#define mrealloc(ptr, size) ((ptr) ? realloc(ptr, size) : malloc(size))
#define nextsize(size) (((size)==0) ? 20 : ((size)*2))
// Infinite time not defined on all os
#ifndef INFTIM
#define INFTIM -1
#endif
//#define DEBUG_TIMEKEEPER
int CTimeKeeperItem::timeKeeperFD(int event){
return FALSE;
}
int CTimeKeeperItem::timeKeeperSetEvents(int event){
if (m_timeKeeper != NULL){
m_timeKeeper->setEvents(this,event);
return 1;
}
return 0;
}
int CTimeKeeperItem::timeKeeperHB(){
return FALSE;
}
CTimeKeeper::CTimeKeeper() {
hbs=NULL;
num_hbs=0; size_hbs=0;
fds=NULL; timeKeeperFD=NULL;
num_fdns=0; size_fds=0;
mintimeout=INT_MAX;
num=0;
running=0;
setTime();
}
CTimeKeeper::~CTimeKeeper(){
}
void
CTimeKeeper::setTime() {
struct timezone tzp;
gettimeofday(&lasttime, &tzp);
}
int
CTimeKeeper::getTime() {
struct timezone tzp;
struct timeval tv;
gettimeofday(&tv, &tzp);
return ((tv.tv_sec-lasttime.tv_sec)*1000
+(tv.tv_usec-lasttime.tv_usec)/1000);
}
int
CTimeKeeper::addFd(int fd, CTimeKeeperItem * fn, short events) {
fn->timeKeeperSetTimeKeeper(this);
if (size_fds<=num_fdns) {
size_fds = nextsize(size_fds);
fds = (struct pollfd *)mrealloc(fds, size_fds*sizeof(struct pollfd));
timeKeeperFD = (CTimeKeeperItem **)mrealloc(timeKeeperFD,size_fds*sizeof(CTimeKeeperItem*));
if ((fds == NULL) | (timeKeeperFD == NULL)){
throw new CException("Out of memory exception");
}
}
fds[num_fdns].fd = fd;
fds[num_fdns].events = events;
fds[num_fdns].revents = 0;
timeKeeperFD[num_fdns] = fn;
num_fdns++;
return 0;
}
#define MYmemmove(a,b,c) cdebug << "Memmove(Dest= " << a << ",Src= " << b << ",Length= " << c << ");\n"; memmove(a,b,c)
int
CTimeKeeper::rmFd(int fd) {
int i = num_fdns-1;
while (i >= 0){
// for (i=0; i<num_fdns; i++) {
if (fds[i].fd == fd) {
#ifdef DEBUG_TIMEKEEPER
cdebug << "CTimeKeeper::rmFD ( " << fd << " ) at pos : " << i << "\n";
#endif
memmove(&fds[i], &fds[i+1], (DWORD)&fds[num_fdns]-(DWORD)&fds[i+1]);
memmove(&timeKeeperFD[i], &timeKeeperFD[i+1], (DWORD)&timeKeeperFD[num_fdns]-(DWORD)&timeKeeperFD[i+1]);
num_fdns--;
return 1;
}
i--;
}
return 0;
}
int CTimeKeeper::setEvents(CTimeKeeperItem * fn,short events){
int i;
for (i=0; i<num_fdns; i++) {
if (timeKeeperFD[i] == fn) {
fds[i].events = events;
return 1;
}
}
return 0;
}
int
CTimeKeeper::addHeartBeat(int timeout, CTimeKeeperItem * fn) {
int nsize, i;
void *nptr;
if (size_hbs<=num_hbs) {
nsize = nextsize(size_hbs);
nptr = mrealloc(hbs, nsize*sizeof(struct heartbeat));
if (!nptr) return 1;
size_hbs = nsize;
hbs = (struct heartbeat *)nptr;
}
/* round down to nearest 2^n */
for (i=0; timeout &= ~(1<<i) ; i++);
timeout = 1<<i;
hbs[num_hbs].timeout = timeout;
if (timeout < mintimeout) mintimeout=timeout;
hbs[num_hbs].fn = fn;
num_hbs++;
return 0;
}
int
CTimeKeeper::rmHeartBeat(CTimeKeeperItem * fn) {
int i, j;
for (i=0; i<num_hbs; i++) {
if (hbs[i].fn == fn) {
memmove(&hbs[i], &hbs[i+1], &hbs[num_hbs]-&hbs[i+1]);
num_hbs--;
mintimeout = INT_MAX;
for (j=0; j<num_hbs; j++) {
if (hbs[i].timeout < mintimeout)
mintimeout=hbs[i].timeout;
}
return 1;
}
}
return 0;
}
void
CTimeKeeper::stopLoop() {
running=0;
}
void
CTimeKeeper::mainLoop() {
running=1;
while (running) {
poll( ((mintimeout == INT_MAX) ? INFTIM : mintimeout) );
}
}
void
CTimeKeeper::poll(int timeOut) {
int nready, i;
nready = ::poll(fds, num_fdns,timeOut);
// cdebug << "Poll : " << nready << "\n";
#ifdef DEBUG_TIMEKEEPER
if (nready > 0){
cdebug << "CTimeKeeper::poll(...)\n";
cdebug << " nready : " << nready << "\n";
i = num_fdns-1;
while (i >= 0){
cdebug << " fds[" << i << "].fd : " << fds[i].fd << "\n";
cdebug << " fds[" << i << "].events : " << fds[i].events << "\n";
cdebug << " fds[" << i << "].revents : " << fds[i].revents << "\n";
cdebug << " timeKeeperFD[" << i << "].getName() : "
<< timeKeeperFD[i]->getName() << "\n";
i--;
}
}
#endif
// for (i=0; nready > 0 && i < num_fdns; i++) {
i = num_fdns-1; // New
while (i >= 0){ // New
if (fds[i].revents) {
// cdebug << "Event : " << fds[i].revents << "\n";
if (!timeKeeperFD[i]->timeKeeperFD(fds[i].revents)){
rmFd(fds[i].fd);
// i--;
} else {
fds[i].revents=0;
}
// nready--;
}
i--; // New
}
if ( getTime() >= mintimeout ) {
for (i=0; i < num_hbs; i++) {
if (!(num % (hbs[i].timeout/mintimeout))) {
if (!hbs[i].fn->timeKeeperHB()){
rmHeartBeat(hbs[i].fn);
i--;
}
}
}
num++;
setTime();
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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 "viewpoint.H"
CViewpoint::CViewpoint(){
}
void CViewpoint::setPosition( const CPosition & position ){
this->position = position;
}
CPosition & CViewpoint::getPosition(){
return position;
}
void CViewpoint::setDirection( const CDirection & direction ){
this->direction = direction;
}
CDirection & CViewpoint::getDirection(){
return direction;
}
void CViewpoint::setTargetId(DWORD targetId){
m_targetId = targetId;
}
DWORD CViewpoint::getTargetId(){
return m_targetId;
}