Create a mud client service program by yourself

Source: Internet
Author: User
Tags telnet program
With the development of the Internet, more and more people are joining in this vibrant online world. As a professional computer player in the network information age, it is extremely important to master network programming. This article introduces Internet network programming and mud knowledge through a mud client service program.
Mud, full name of multiple user dungeon, is a multi-user "dungeon" game. Currently, worms generally call it muba. If you already have access to the network, you can add a mud address and port after you know it. In the Windows 95 operating system, you can use the "telnet address port" command to log on to the mud. However, the telnet program of Windows 95 is not dedicated to mud, so it is very inconvenient to use, this is mainly because Telnet cannot process text redirection, and because the input and output are in the same window, the input and output information is mixed together, making it difficult for users to identify. Historical input cannot be reused, which greatly increases user input. In addition, the server sends you a lot of control information in mud to change the color or highlight of the output text, which is simply ignored by Telnet. In view of these inconveniences, some programmers have developed mud client service programs which generally have these functions:
* Connect to mud --- this is a basic function
* Command line history-reusable previous commands
* Macro command --- replace long commands with macros
* Separate input and output windows to avoid confusion between input and output information
* Back-to-volume of output information --- allows you to view previous output information
* Emphasizing display --- handling control sequence sent from Mud System
There are some more advanced features:
* Automatic Logon --- automatically log on to mud based on user history
* Multiple connections-allow simultaneous connection to multiple muds or simultaneous logon to multiple users on one mud
* Trigger device-automatically issue a command under certain circumstances
* Automatic Navigation System-generate a logical map by recording commands such as east, west, south, north, up, and down, and automatically navigate users to a certain place
* Programming interface-user programmable, robot creation, instead of user hard work on Mud
The mud client service programs in DOS/Windows mainly include mudcaller and bsxmud. Among them, zmud of zugg software is popular and easy to use, next we will use VB to create our own mud client.
First, we will introduce the Winsock Control. In VB, the Winsock control can be used to establish a connection with a remote computer and exchange data through the user's TCP or UDP protocol. Both protocols can be used to create client and server applications. When creating a mud client, we use the TCP protocol. After assigning values to the remotehost and remoteport of the control, you can call the connect method to connect to the mud host. Then, use getdata and senddata to talk to the mud host. The data sent from the mud host is the ASCII text containing the escape control string. When talking about the escape control string, you need to explain it, the escape control string is a string of characters starting with escape (ASCII 27/0 x1b) and '[' in ANSI for keyboard control and display control, in mud, only setting the output attribute is involved. In escape and '[', it is followed by A1; A2 ;... 'M'. The string ends with the character M. A1, A2, and so on are numbers, meaning:
0: Restore the black/white display;
1: High Brightness Display
2: normal display
30 .. 37: black, red, green, yellow, blue, foreign red, blue, white
For example, CHR (27) [1; 31m indicates that the display is highlighted in red from here, while CHR (27) [2; 37; 0m indicates that the black and white display mode is restored and normal white display is used.
Now we Open VB, create a standard project, select project | part menu, and add the Microsoft WinSock control 5.0 and Microsoft Rich Textbox Control 5.0 controls to the toolbar.
Rename form1 to fmud, drag a commandbutton from the toolbar to fmud, rename it cmdsend, and set its default attribute to true. Drag a Rich Textbox to fmud and rename it mudout. Set the text attribute to null and scrollbars to rtfboth. Drag a ComboBox to fmud and rename it mudin. Set the text attribute to null. Drag a Winsock Control to fmud and rename it mudsock .. The next step is to use the menu editor to create a menu for fmud. One sub menu is called connect, and the main window is ready.
Add a new form to the project, named fconnect, to receive the address and port of the mud host to which the user is to be linked. First, put two labels on the top, respectively set caption to "mud address:" and "port:", and then put the two textbox named taddress and tport respectively, set the location, make the two labels point to two Textbox, and put a commandbutton at the end to make it name = connect, caption = "& connect", default = true, enabled = false. Now let's start programming:
Fmud window:
Fmud definition:
Dim bconnected as Boolean
Connect menu:
If not bconnected then
Fconnect. Show 1
Mudsock. Connect 'to the mud host
Bconnected = true
Mudin. setfocus
End if
Fmud load event:
Bconnected = false
The resize event of fmud:
Mudout. Top = 0' adjust the widget's position to the size
Mudout. Left = 0
Mudout. width = fmud. Width-120
Mudout. Height = fmud. Height-700
Mudin. Top = mudout. height + 20
Mudin. Left = 0
Mudout. width = fmud. Width-120
Dataarrival event of mudsock:
Dim strdata as string
If connected then
Mudsock. getdata strdata' fetch data from the mudsock Buffer
Mudout. Text = mudout. Text + strdata
Mudout. selstart = Len (mudout. Text)
If Len (mudout. Text)> 2000 then' buffer 2000 characters of Text
Mudout. Text = right (mudout. Text, 2000)
End if
ENE if
Cmdsend click event:
Dim s as string
Dim I as integer
S = mudin. Text + CHR (13) & CHR (10) 'Add a carriage return line to the command line
Fmud. mudsock. senddata s
For I = 1 to mudin. listcount
If mudin. List (I) = mudin. Text then
Mudin. removeitem (I) 'Delete repeated historical commands
End if
Next I
If mudin. listcount> 30 then' buffer 30 historical commands
Mudin. removeitem 0
End if
Mudin. additem mudin. text' add this command to the end of the History
Mudin. selstart = 0
Mudin. sellength = Len (mudin. Text) 'command text is selected
'When you enter a command, you can directly type
Fconnect window:
Change event of taddress and fport:
If (taddress. Text <> "") and (tport. Text <> "") then
Required connect. Enabled = true
Else
Required connect. Enabled = false
End if
Click Event of the Connect button:
Fmud. mudsock. remotehost = taddress. Text
Fmud. mudsock. remoteport = CINT (tport. Text)
Fconnect. Hide
Now you can use the mud client service program to connect to the mud. However, due to space limitations, the current function of this program is only to output information back-to-volume, separate input and output and reuse History commands, it is better than telnet to play mud. In addition, to support the highlighted display function, you only need to identify the escape ['control string from the message string sent from the mud host, and use the selcolor method of RichTextBox to set the text color, this is why RichTextBox is used instead of textbox. Finally, it is pointed out that whether the Winsock connect connection is correct should be programmed in the mudsock onerror event. This program is omitted.
If you are interested in the mud client or mud, visit the author's homepage: http://fanzhang.yeah.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.