Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUDs ➜ General ➜ Tiny MUD Server - version 2

Tiny MUD Server - version 2

Posting of new messages is disabled at present.

Refresh page


Pages: 1  2  3  4  5  6  7  8 

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #105 on Mon 04 Oct 2010 03:40 AM (UTC)
Message
I've added the output iterator to the Git repository:

http://github.com/nickgammon/tinymudserver/commit/98a4e65e14


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #106 on Mon 04 Oct 2010 05:59 AM (UTC)

Amended on Mon 04 Oct 2010 08:43 PM (UTC) by Nick Gammon

Message
The thing that bothers me a bit about the output iterator on the previous page is that it has the tPlayer type hard-coded into it. A bit of juggling and you can make an output iterator for any type:


template <typename CharT>
class generic_output_iterator : public std::iterator <std::output_iterator_tag, CharT, void, void, void>
{
 protected:
   CharT      & item_;     // item we are outputting to
   const char * delim_;    // delimiter between each thing output
   
 public:
  // constructor
  generic_output_iterator (CharT & c, const char* d = "")
    : item_ (c), delim_ (d) { }
  
  // copy constructor
  generic_output_iterator (const generic_output_iterator & rhs)
    : item_ (rhs.item_), delim_ (rhs.delim_) { }
  
  // assignment - outputs to item_, followed by delim_
  template <typename Tp>
  generic_output_iterator & operator= (const Tp & rhs)
    { 
    item_ << rhs << delim_;  
    return *this;
    }  // end of operator=
  
  // dereference
  generic_output_iterator & operator* ()     { return *this; }
  // pre increment
  generic_output_iterator & operator++ ()    { return *this; }
  // post increment
  generic_output_iterator & operator++ (int) { return *this; }
};  // end of generic_output_iterator


typedef generic_output_iterator<tPlayer> player_ostream_iterator;


void DoShowFlags (tPlayer * p, istream & sArgs)
{
  tPlayer * ptarget = p->GetPlayer (sArgs, "Usage: showflags <who>");  // who
  NoMore (p, sArgs);  // check no more input
  *p << "Flags for " << ptarget->playername << " : ";
  std::copy (ptarget->flags.begin (), ptarget->flags.end (), player_ostream_iterator (*p, " "));
  *p << "\n"; 
      
} // end of DoShowFlags


The templated class generic_output_iterator now makes an output iterator for any type. The output type is automatic because that is templated inside the iterator.

Then the line in bold creates a player_ostream_iterator specifying the class to output to (tPlayer). Then the copy function in DoShowFlags can be simpler because we no longer need to specify that we are sending a string to the iterator.

[EDIT] Tidied up a bit to take an automatic output stream type (eg. string).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kyle Chappetta   (3 posts)  Bio
Date Reply #107 on Fri 22 Oct 2010 03:16 PM (UTC)

Amended on Fri 22 Oct 2010 03:26 PM (UTC) by Kyle Chappetta

Message
Howdy. I wasn't sure where to post this, so I posted it here. I've downloaded Tiny Mud from GitHub, but I ran into a compile error that I don't know how to correct. Below is the log from my terminal when I typed "make". Can anyone help?

kyle@ubuntu:~/Downloads/tinymudserver$ make
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c tinymudserver.cpp
g++ -MM tinymudserver.cpp > tinymudserver.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c strings.cpp
g++ -MM strings.cpp > strings.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c player.cpp
g++ -MM player.cpp > player.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c load.cpp
g++ -MM load.cpp > load.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c commands.cpp
g++ -MM commands.cpp > commands.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c states.cpp
g++ -MM states.cpp > states.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c globals.cpp
g++ -MM globals.cpp > globals.d
g++ -g3 -Wall -w -pedantic -fmessage-length=0 -c comms.cpp
comms.cpp: In function 'int InitComms()':
comms.cpp:104: error: 'perror' was not declared in this scope
comms.cpp: In function 'void ProcessNewConnection()':
comms.cpp: 211: error: 'perror' was not declared in this scope
comms.cpp:219: error: 'perror' was not declared in this scope
make: *** [comms.o] Error 1

Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #108 on Fri 22 Oct 2010 07:56 PM (UTC)
Message
Fixed in latest commit:

http://github.com/nickgammon/tinymudserver/commit/03e003403e

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Martin4503   (2 posts)  Bio
Date Reply #109 on Wed 12 Mar 2014 10:28 PM (UTC)

Amended on Thu 13 Mar 2014 02:35 AM (UTC) by Martin4503

Message
Hi Nick.

Is this server ipv6 compatible? If it isn't, how I can add support for ipv6?
Top

Posted by Journey   (1 post)  Bio
Date Reply #110 on Sun 03 Aug 2014 11:50 AM (UTC)
Message
I hope there's still someone here. :)

I'm wondering if anyone ever coded a "look (thing)".

In the commands.cpp file I see this:

void DoLook (tPlayer * p, istream & sArgs)
{

// TODO: add: look (thing)

I realy need the ability to look at a 'thing' that I've defined in the rooms.txt file as a new line after the exits.

It would save me a lot of time if anyone has a snippet or two for me.

Thanks!!
Jack
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #111 on Sun 03 Aug 2014 08:34 PM (UTC)
Message
I got your message on Facebook but I don't want to have technical discussions there. :)


To look at an object first objects (things) need to exist (which they don't as I recall). So you would need to make a datatype for an object, then make it so they can be in a room, or in someone's inventory (or a mob's inventory).

You would pick up an object by removing it from the list in the room and adding it to the list in the inventory. Dropping it would be the reverse process.

To get you started with the syntax of looking, you can modify DoLook to see if there is an argument (eg. "look sword") and if so pass control to another function that looks at that thing. Example code below.


void lookObject (tPlayer * p, string & which)
  {
  *p << "Looking at object " << which << "\n";

  // scan available objects and display information about them ...

  }  // end of lookObject

/* look */

void DoLook (tPlayer * p, istream & sArgs)
{
 
  // look (thing)

  string whichObject;
  sArgs >> ws >> whichObject;

  if (!whichObject.empty ())
    {
    lookObject (p, whichObject);
    return;
    }
    
  
  // find our current room, throws exception if not there
  tRoom * r = FindRoom (p->room);
  
...


I warn you that this sort of stuff can get complex quite quickly. For example, you probably need a "template object" (eg. a sword) and then an instance of that object (a particular sword held by a particular mob). Also you have to modify the game load/save code to remember their inventory.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


344,715 views.

This is page 8, subject is 8 pages long:  [Previous page]  1  2  3  4  5  6  7  8 

Posting of new messages is disabled at present.

Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.