How do you use telnet to connect to a game of mine and use commands to do things in the game?
~Blaz3
ID:189733
May 27 2003, 3:43 pm
|
|
May 27 2003, 8:08 pm
|
|
You'd telnet to the same IP address and port number that the game is being hosted on. Remember that a lot of BYOND's features can't be used in telnet, though.
|
Blaz3 wrote:
How do you use telnet to connect to a game of mine and use commands to do things in the game? You cannot use verbs when connecting from telnet. You connect by telnetting to the IP and the Port of the host. To enter commands in telnet, you need to use client/Command(). Its not documented, but any input from a client will go to client/Command() as its only argument, and its up to you to parse it from there. For more information, you may want to check out some different parsers made by people (AbyssDragon's for example, or Ebonshadow's), and (shameless publicity plug)The MUD Corner(/shameless publicity plug) |
In response to Alathon
|
|
Alathon wrote:
Blaz3 wrote: Thanks, that's EXACTLY what I needed =) ~Blaz3 |
In response to Blaz3
|
|
I'm giving up. It's all to confusing. Thanks for the help anyway.
~Blaz3 |
When you input something into a BYOND program through telnet, that input (a text string), gets sent through client/Command(). If you want to make the program a telnet application, you need to override client/Command() and direct the input to your own parser program that converts to text string into something that the program can understand. Here's how you override the client/Command() proc.
<code>client Command(message as command_text|null) if(message) Parse(Message)</code> But that won't do much if you don't have a Parse() proc to go with it, so we need to make one of those. But how do you create one of those? Generally, you begin by creating a proc that converts the text string into a list() of words, so that you can work with each word in the message individually. I happen to have one of those handy. <code>proc/text2string(message, divider = " ") if(!message) return message += divider var/list/string = list() while(findtext(message, divider)) var/position = findtext(message, divider) string += copytext(message, 1, position) message = copytext(message, position+1) return string</code> And just for completeness sake, here's one that converts the list() of words into a text string again. <code>proc/string2text(list/string, divider = " ") var/text = "" for(var/word in string) text += (word + divider) return copytext(text, 1, length(text) - lentext(divider) + 1)</code> Now that you have those, you can create a Parse() proc by having it read the first word item in the new word list (the first word in the message), and determining which command needs to be run based on what the input was, or whether an error message needs to be sent to the player because there were not valid commands for that word. <code>client/Parse(message) var/list/arguments = text2string(message) var/command = arguments[1] // the first word arguments.Remove(command) switch(lowertext(command)) if("say") mob.Say(arguments) if("look") mob.Look(arguments) if("get") mob.Get(arguments) if("eat") mob.Eat(arguments) else usr << "I don't understand, '[command]'."</code> There are many ways you can improve upon that, but I want to keep it based for now. Its better to learn the basic functions, then improve on them. Oh, and each command after that has to work with the arguments, and should look somethnig like this: <code>mob/Say(list/arguments) var/message = string2text(arguments) usr << "You say, '[message]'" oview() << "[src] says, '[message]'" return</code> That's a start, anyway. |
In response to Foomer
|
|
Wow! Thanks =)
~Blaz3 |
In response to Foomer
|
|
Don't suppose you would mind re-posting that on MUD Corner ? Could use some tutorial-like material for newbies, thats what its currently lacking the most (Besides a theme overhaul). I am in the process of writing a small document on it myself, but im bad at explaining things like this, so im sure your little exerp would be appreciated.
|
In response to Foomer
|
|
old thread but I need help!!
What am i doing wrong, none of this works for me, I also get a few errors trying to compile your code. Ive used other versions of parsers that I've found on the forums but none of them work (error free though). I can telnet to the server but no data is recieved on either side. I wrote a verb that lists all the mobs connected to the server, but it only lists the accounts that are connected using DS not telnet. [EDIT] Ok, Its a problem with my ports... I had DS run in a random port and it was working then I restart the server and it wasnt working. I turned off my firewall but that hasnt helped and I cant remember what port it was that was working. Anyone have any ideas on what I can do? |