Top Mud Sites Forum Return to TopMudSites.com
Go Back   Top Mud Sites Forum > Mud Development and Administration > MUD Coding
Click here to Register

Reply
 
Thread Tools
Old 08-19-2004, 06:32 AM   #1
Khadgar
New Member
 
Join Date: Mar 2003
Posts: 29
Khadgar is on a distinguished road
Khadgar is offline   Reply With Quote
Old 08-19-2004, 09:49 AM   #2
Darrik
New Member
 
Join Date: Apr 2002
Posts: 25
Darrik is on a distinguished road
Darrik is offline   Reply With Quote
Old 08-19-2004, 11:59 AM   #3
Razzer
New Member
 
Join Date: Jan 2003
Posts: 3
Razzer is on a distinguished road
The simplest would just be a linear socket pattern. It roughly goes something like this

Create server socket (somewhat like you have)
Loop while game is running
Check sockets (look up select())
If new connection is waiting, accept connection
Read new data, parse, and send output.
End loop

Something similar to that pattern. Multithreading might be a challenge that you might not want to take if you don't fully understand BSD sockets. Using asynchronous socket on a TCP stream is unwise, so scratch that option.

It is a bit of a hack. The second paramenter of bind() takes a struct sockaddr pointer. In order for many different socket family and types to be used, different structures (like sockaddr_in) need to be cast to a struct sockaddr pointer.

[code] service.sin_addr.s_addr = inet_addr("127.0.0.1");[/quote]

Instead of inet_addr("127.0.0.1"), you'd probably be better off with INADDR_ANY.

[code] m_socket = AcceptSocket;[/quote]

You won't want to do this in a real MUD. This reassigned the variable m_socket with AcceptSocket, so it completely loses whatever value it had before. The problem is that the value it had before was the descriptor to the server you had just made, and by the reassignment you have lost the server descriptor.
Razzer is offline   Reply With Quote
Old 08-20-2004, 10:23 AM   #4
Kastagaar
Member
 
Join Date: Apr 2002
Location: Hampshire, UK
Posts: 117
Kastagaar is on a distinguished road
Send a message via Yahoo to Kastagaar
The multiplexing function you are looking for (and is found in the above tutorials) is "select()". It takes arguments including sets of socket file descriptors, and tells you which of those has data that can be read without blocking the program flow.
Kastagaar is offline   Reply With Quote
Old 08-22-2004, 08:14 PM   #5
Khadgar
New Member
 
Join Date: Mar 2003
Posts: 29
Khadgar is on a distinguished road
was really useful as Darrik mentioned.  I must admit I was a little turned off at the thought of coding sockets at first, but it isn't as hard as I thought it would be.  I suppose the disadvantage with using the select() function would be it takes longer than multithreaded applications because it processes one request at a time.  Nevertheless, i think it will work quite well on an efficient server.

Thanks to those who responded with my first set of questions.  However, I have a few more questions regarding networking:

1)  Is there a way to determine a client's screen width and height?  If so, how would I go by doing this?  

2) Is there a way to get and set a client's console cursor position?  I'd like to have the automapper and room description side by side without recoding them.  

3) How would you go by coloring characters over a network?  

4) How do you prevent certain players from logging onto your server?  How exactly do you ban them?  Hostname? IP address?

I know how to do 1-3 with my own computer, but when it comes to networking, I don't know what functions to use.  Any good references or code examples will be greatly appreciated.  Once again, thanks in advance to those who help.
Khadgar is offline   Reply With Quote
Old 08-22-2004, 09:22 PM   #6
Razzer
New Member
 
Join Date: Jan 2003
Posts: 3
Razzer is on a distinguished road
What do you mean? select() looks at all the sockets (well... really techy detail says otherwise, but just assume it does) it is passed.

I assume you would be interested in more of a reference than exact code so which you can be able to write the appropiate code yourself. You can always come back and ask, but I think the reference will do you go in the long run.

So, with that said, I would check out (I hope you like pink.) Click on the SocketsProgramming link on the bottom left-hand corner. Then go to the section "Terminal/ANSI". Those are references that probably should get you to a start. If you can't understand them, just go ahead and write a nasty e-mail to the site administrator on how he is unable to provide helpful links ().

Easiest way is like this:

Accept new connection.
Get IP address of connection.
Compare it to the list of banned IP addresses.
Kick if there is a match.
Razzer is offline   Reply With Quote
Old 08-23-2004, 04:44 AM   #7
Kastagaar
Member
 
Join Date: Apr 2002
Location: Hampshire, UK
Posts: 117
Kastagaar is on a distinguished road
Send a message via Yahoo to Kastagaar
On the contrary. select() works on sets of sockets, so with a good design its quite possible to poll all of your inbound sockets to see who is ready to be read.

Read up on and its option that most clients support.

You'll need to use ANSI escape codes for these. has a good list. The one you're interested in is <ESC>[6n.

Yes.
Kastagaar is offline   Reply With Quote
Old 08-23-2004, 06:47 AM   #8
Khadgar
New Member
 
Join Date: Mar 2003
Posts: 29
Khadgar is on a distinguished road
Khadgar is offline   Reply With Quote
Old 08-23-2004, 08:34 AM   #9
Kastagaar
Member
 
Join Date: Apr 2002
Location: Hampshire, UK
Posts: 117
Kastagaar is on a distinguished road
Send a message via Yahoo to Kastagaar
This is only true on a machine with multiple processors. A single-processor machine (HyperThreading P4s notwithstanding) will still have to execute the threads sequentially one way or another, even if it's in a lot of tiny little sub-sequences.

Any time.
Kastagaar is offline   Reply With Quote
Old 08-23-2004, 11:51 AM   #10
Razzer
New Member
 
Join Date: Jan 2003
Posts: 3
Razzer is on a distinguished road
Razzer is offline   Reply With Quote
Old 08-23-2004, 08:02 PM   #11
karlan
Member
 
Join Date: Apr 2002
Location: Brisbane Australia
Posts: 74
karlan is on a distinguished road
Multithreading also favours players with faster connections... I consider that a bad thing, alot of my friends from school are living in remote areas with unreliable access via telephone, and ADSL or cable is just a pipe dream, and I know I would quickly stop playing a MU if I was disadvantaged that way. In addition you'll have to be very very carefull with critical section control if you multithread. It will be possible for char data to get well out of sync, if 2 threads are updating a chars health at the same time, which one will be used (or possibly both)
karlan is offline   Reply With Quote
Reply


Thread Tools


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -4. The time now is 10:55 AM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Style based on a design by Essilor
Copyright Top Mud Sites.com 2022