Top Mud Sites Forum

Top Mud Sites Forum (http://www.topmudsites.com/forums/index.php)
-   MUD Coding (http://www.topmudsites.com/forums/forumdisplay.php?f=9)
-   -   Sockets (http://www.topmudsites.com/forums/showthread.php?t=368)

Khadgar 08-19-2004 06:32 AM


Darrik 08-19-2004 09:49 AM


Razzer 08-19-2004 11:59 AM

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.

Kastagaar 08-20-2004 10:23 AM

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.

Khadgar 08-22-2004 08:14 PM

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.

Razzer 08-22-2004 09:22 PM

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 (:D).

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.

Kastagaar 08-23-2004 04:44 AM

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.

Khadgar 08-23-2004 06:47 AM


Kastagaar 08-23-2004 08:34 AM

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.

Razzer 08-23-2004 11:51 AM


karlan 08-23-2004 08:02 PM

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)


All times are GMT -4. The time now is 12:50 PM.

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Top Mud Sites.com 2022