MUD Game Programming

Posted by Conap on Sat 26 Nov 2005 11:06 PM — 13 posts, 46,139 views.

#0
Hello, I just want to know with what compiler I can compile the MUDs example in the book ?
Australia Forum Administrator #1
I compiled it OK with Cygwin. After compiling it and connecting to port 5100 I saw this:


--- Connected on Monday, November 28, 2005, 7:18 AM ---
Welcome To SimpleMUD v1.0
Please enter your name, or "new" if you are new: 
new
Please enter your desired name: 
nick
Please enter your desired password: 
nick
Thank you! You are now entering the realm...
nick has entered the realm.
[10/10] Welcome to SimpleMUD, nick!
You must train your character with your desired stats,
before you enter the realm.


--------------------------------- Your Stats ----------------------------------
Player:           nick
Level:            1
Stat Points Left: 18
1) Strength:      1
2) Health:        1
3) Agility:       1
-------------------------------------------------------------------------------
Enter 1, 2, or 3 to add a stat point, or "quit" to enter the realm: 

#2
Can you add your Cygwin makefile ?
Australia Forum Administrator #3
I just used the one that came with it. There is a readme.txt file, do what it says. Specifically:

Quote:

GCC: type "make libs", "make simplemud", and "make link"

Amended on Thu 01 Dec 2005 07:05 PM by Nick Gammon
Australia #4
I have tryed to compile the examples in that book (Simple and Better)a number of times to no avail. What version of G++ are you using in cygwin Nick? If i remember rightly, i tryed using G++3.4 and it wouldnt even compile the first lib file due to the inconcistancies between 2.95 and 3x. And following the examples of how to get it to compile in MVC worked with a Million warnings, but then would then complain about the Python2.2 library being missing, i was sort of turned off this book because of the difficulty of getting it to compile. I guess i should try again and pick your brains to get it working.
Australia Forum Administrator #5
I tried simple, I didn't want to muck around with Python right then.


$ gcc --version
gcc (GCC) 3.3.1 (cygming special)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Australia #6
Ok, finnally found 10 minuites to have a play with this. Here is a short list of the errors i get on trying to compile simplemud library files in G++4.0, from memory these were the same sorts of errors i was getting with G++3.x as well.

g++ -I./Libraries ./Libraries/SocketLib/*.cpp -c;
./Libraries/BasicLib/BasicLibRandom.h: In member function 'double BasicLib::normal_generator<inclusive, generator>::operator()()':

./Libraries/BasicLib/BasicLibRandom.h:132: error: there are no arguments to 'log' that depend on a template parameter, so a declaration of 'log' must be available
./Libraries/BasicLib/BasicLibRandom.h:132: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undecla red name is deprecated)

m_rho = sqrt(-2 * log(1- m_rho2));

./Libraries/BasicLib/BasicLibRandom.h:140: error: there are no arguments to 'cos' that depend on a template parameter, so a declaration of 'cos' must be available
./Libraries/BasicLib/BasicLibRandom.h:140: error: there are no arguments to 'sin' that depend on a template parameter, so a declaration of 'sin' must be available

return m_rho * ( m_valid ? cos(2 * pi * m_rho1) : sin( 2 * pi * m_rho1)) * m_sigma + m_mean;



./Libraries/SocketLib/ConnectionManager.h: At global scope:
./Libraries/SocketLib/ConnectionManager.h:37: error: type 'std::list<SocketLib::Connection<protocol>, std::allocator<SocketLib::Connection<protocol> > >' is not derived from type 'SocketLib::ConnectionManager<protocol, defaulthandler>'
./Libraries/SocketLib/ConnectionManager.h:37: error: expected ';' before 'clistitr'

 typedef std::list< Connection<protocol> >::iterator clistitr;


./Libraries/SocketLib/ConnectionManager.h:110: error: 'clistitr' has not been declared
./Libraries/SocketLib/ConnectionManager.h: In destructor 'SocketLib::ConnectionManager<protocol, defaulthandler>::~ConnectionManager()':

 void Close( clistitr p_itr );


./Libraries/SocketLib/ConnectionManager.h:161: error: 'clistitr' was not declared in this scope
./Libraries/SocketLib/ConnectionManager.h:161: error: expected `;' before 'itr'

clistitr itr;


There are a lot more errors than this, but a lot of them seem to be about these few things.

Thanks in advance.

Australia #7
A side note to further this story, i installed gcc2.9x and can make both Simple and Better compile, not that i am having any better luck with either of these, as the a.out executable seems to run, the process shows up in ps -uxw and seems to be using some resources, but they do not accecpt any connections. telneting into localhost 5100 or 5110 in the case of better mud, does nothing, telnet connects and just sits there.
Australia Forum Administrator #8
Using their Makefile I got a file SimpleMUD.exe, not a.out.
Australia #9
Are you certain that the SimpleMUD.exe file that you have was created by the make process or the one that comes with the package precompiled?

As i can run that file, but if i delete it and remake, i only get a file a.out which is also what the book says i should get.


# Compiler is G++
CXX = g++

#MUDLib directory
MUDLIBDIR = ../Libraries
SOCKETLIBDIR = $(MUDLIBDIR)/SocketLib
THREADLIBDIR = $(MUDLIBDIR)/ThreadLib
BASICLIBDIR  = $(MUDLIBDIR)/BasicLib
SIMPLEMUDDIR = ./SimpleMUD

# libraries
LIBS = -lpthread

# flags
CFLAGS = -I$(MUDLIBDIR)

libs: $(wildcard *.cpp)
	$(CXX) $(CFLAGS) $(SOCKETLIBDIR)/*.cpp -c;
	$(CXX) $(CFLAGS) $(THREADLIBDIR)/*.cpp -c;
	$(CXX) $(CFLAGS) $(BASICLIBDIR)/*.cpp -c;

simplemud: $(wildcard *.cpp)
	$(CXX) $(CFLAGS) *.cpp -c;
	$(CXX) $(CFLAGS) $(SIMPLEMUDDIR)/*.cpp -c;

main: $(wildcard *.cpp)
	$(CXX) $(CFLAGS) *.cpp -c;

link: $(wildcard *.cpp)
	$(CXX) $(CFLAGS) *.o $(LIBS)


Australia Forum Administrator #10
You are right, the .exe was already there.

Well I have spent a considerable time trying to get the program to compile under gcc, let alone run.

I found, after compiling it, the exact same results you did, that it would just "hang" if you connected to it. However if you aborted the server the client would say "lost connection" so clearly something was happening.

I suspected it hadn't recognised the new connection, which turned out to be the case. It's funny the author never noticed it.

Anyway, the offending line is in SocketLib/SocketSet.h (line 43 in my version):

Change:


return select( *(m_socketdescs.rbegin()), &m_activityset, 0, 0, &t );



To:


return select( *(m_socketdescs.rbegin()) + 1, &m_activityset, 0, 0, &t );


It took me a while to work out what he was doing there. The critical line is from the help for "select" which reads:


n is the highest-numbered descriptor in any of the three sets, plus 1.


socketdescs is declared as a set of sockets, like this:


std::set<sock> m_socketdescs;


*(m_socketdescs.rbegin()) is going to return the highest socket in the set. However it needs to be that number, plus one. Thus, I have put the "+ 1" into that line.

Also, to get rid of the compiler warnings, I made these changes:



diff -c ../SimpleMUD 1.0.1/SimpleMUD/EntityDatabase.h SimpleMUD/EntityDatabase.h
*** ../SimpleMUD 1.0.1/SimpleMUD/EntityDatabase.h	2005-12-07 13:33:34.000000000 +1100
--- SimpleMUD/EntityDatabase.h	2005-12-07 12:04:15.000000000 +1100
***************
*** 50,58 ****
          // Have I mentioned that VC6 sucks yet?
          // --------------------------------------------------------------------
          iterator() {};  // default constructor
!         iterator( typename const container::iterator& p_itr ) // copy constructor
          {
!             container::iterator& itr = *this; // also needed because VC6 sucks
              itr = p_itr;
          }
  
--- 50,58 ----
          // Have I mentioned that VC6 sucks yet?
          // --------------------------------------------------------------------
          iterator() {};  // default constructor
!         iterator( const typename container::iterator& p_itr ) // copy constructor
          {
!             typename container::iterator& itr = *this; // also needed because VC6 sucks
              itr = p_itr;
          }
  
***************
*** 62,68 ****
          // --------------------------------------------------------------------
          inline datatype& operator*()
          {
!             container::iterator& itr = *this; // also needed because VC6 sucks
              return itr->second;
          }
  
--- 62,68 ----
          // --------------------------------------------------------------------
          inline datatype& operator*()
          {
!             typename container::iterator& itr = *this; // also needed because VC6 sucks
              return itr->second;
          }
  
***************
*** 72,78 ****
          // --------------------------------------------------------------------
          inline datatype* operator->()
          {
!             container::iterator& itr = *this; // also needed because VC6 sucks
              return &(itr->second);
          }
      };  // end iterator inner class
--- 72,78 ----
          // --------------------------------------------------------------------
          inline datatype* operator->()
          {
!             typename container::iterator& itr = *this; // also needed because VC6 sucks
              return &(itr->second);
          }
      };  // end iterator inner class
***************
*** 162,168 ****
  
          entityid openid = 0;
          entityid previous = 0;
!         std::map<entityid,datatype>::iterator itr = m_map.begin();
  
          while( !openid )
          {
--- 162,168 ----
  
          entityid openid = 0;
          entityid previous = 0;
!         typename std::map<entityid,datatype>::iterator itr = m_map.begin();
  
          while( !openid )
          {
***************
*** 189,195 ****
  public:
  
      // internal iterator
!     typename typedef std::vector<datatype>::iterator iterator;
  
      inline static iterator begin()  { return m_vector.begin() + 1; }
      inline static iterator end()    { return m_vector.end(); }
--- 189,195 ----
  public:
  
      // internal iterator
!     typedef typename std::vector<datatype>::iterator iterator;
  
      inline static iterator begin()  { return m_vector.begin() + 1; }
      inline static iterator end()    { return m_vector.end(); }




He doesn't seem to have a high opinion of VC6 :).

I compiled this under:


gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)


I suspect you may have problems with other versions of gcc, however I have had enough of this program for today. :)
Amended on Wed 07 Dec 2005 01:41 AM by Nick Gammon
Australia Forum Administrator #11
I found his updated source (however which does not include the changes I mentioned) at:

http://ronpenton.net/projectfiles/programming/2004-11%20-%20MUDS%201.0.1%20(closed)/MUDs%201.0.1.zip
Australia #12
HEHE, thanks nick, I apreciate the effort you have made in reguard to this program, i will add in your changes and see if i can get it to work.

I downloaded the updated source last night and had the same trouble.

This book has so much potential for people like myself who are not programmers nor students of some programming degree but who can learn from others and expand on their ideas. But rather than having enjoyed this book, i have found it to be a total pain in the ass.

With some help from the wonderfull people in this comunity, i think i might update the source and make it available for download, just incase someone else wishes to give this book a go.