Do it yourself to make MUD client service

zhaozj2021-02-11  189

With the development of the Internet, more and more people join this online world full of infinite vibrant, as a professional computer player in the era of network information, and master network programming is particularly important. This article introduces you some knowledge of Internet Network Programming and MUD through a MUD Client Server.

MUD, full name Multiple User Dungeon, means a multi-user "Dungeon" game, now Networms typically call it mud. If you have already gotten the net, when you know a MUD address and port, you can join this MUD. Under the Windows95 operating system, you can log in to MUD with the "Telnet address port" command. But because the Telnet program of Windows95 is not specifically used to play MUD, it is very inconvenient, which is mainly because Telnet cannot handle the text of the text, and because the input output is in the same window, the input and output information is mixed together, users Identify difficulties. The history input cannot be reused, which greatly increases the user's input. Moreover, there are many control information transmitted to your information to you in the MUD to make the output text change color or highlight, which is simply ignored by Telnet, in view of these inconvenience, some programmers have developed MUD client service. Procedures, these programs generally have these features:

* Connect to MUD - this is the basic function

* Command line history --- can reuse the previous command

* Macro command --- with a long command

* Enter the output window separate --- Avoid input and output information confusion

* Output information Back - Allow to view the previous output information

* Emphasize the display --- can handle control sequences from MUD systems

There are some more advanced features:

* Automatic login --- Automatically log in to MUD according to user history

* Multiple connections --- Allows the simultaneous connection to multiple MUDs, or log in to multiple people on a MUD

* Trigger device - in some case, automatically issuance of a command

* Automatic navigation system --- Generate a logical map by recording EAST, West, South, North, Up, Down, etc., and automatically navigate users to go to a place

* Provide programming interface - users can programmatically, make robots, instead of user hard work in MUD

The MUD client service program under DOS / Windows mainly has Mudcaller, BSXMUD, etc., which is more popular with ZUGG Software's ZMUD, it is also useful, and we use VB to make a Our own MUD Client.

First introduce the WINSOCK control. In VB, the Winsock control can be used to establish a connection with the remote computer, and data exchange is performed by the user TCP or UDP protocol. Both protocols can be used to create clients and server applications. When you create a MUD client, we use TCP protocols. After the Remotehost and RemotePort of the control, you can connect to your CONNECT method to connect to the MUD host. Then use getData and sendData to talk to the MUD host. The data from the MUD host is an ASCII text that comes with the Escape control string. It is said that the Escape control string is explained. The so-called ESCAPE control string is an ESCAPE (ASCII) for keyboard control and display control in ANSI. 27 / 0x1b) and a string of characters at the beginning of '[', generally only involve setting output attributes in MUD, followed by ESCAPE and '[', followed by A1; A2; ... 'm', the string ends with character m, A1, A2, etc. are numbers, the significance is as follows: 0: Restore black and white display;

1: High brightness display

2: Normal display

30 ... 37: Black, Red, Green, Yellow, Blue, Ocean Red, Blue, White

Such as: CHR (27) [1; 31M means that the bright red display from here, while CHR (27) [2; 37; 0M represents the restoration of black and white display mode and display it with ordinary white.

Now we open VB, build a new standard engineering, select Project | Parts menu, join the two controls to Microsoft Winsock Control 5.0 and Microsoft Rich TextBox Control 5.0 into the toolbar.

Return Form1 to fmud, drag from the toolbar on the FMUD, change your name to cmdsend, set its default attribute to true. Drag a Rich TextBox to FMUD, change the name called MUDOUT, set its text property empty, Scrollbars is RTFBOTH. Drag one of the ComboBox to FMUD, change the name called Mudin, and set the text property empty. Finally, drag a Winsock control to FMUD, change your name to Mudsock. The next step is to make a menu with the menu editor, where there is a submenu named Connect, the main window is done.

Add a new form below to change the name of the MUD host address and port for receiving the user to contact. First put two Label on the top, set CAPTION to "MUD Address:" and "Port:", then put two TextBoxs, named taddress and tport, put the two Label points to two textbox, last Put a CommandButton to make it name = cmdconnect, caption = "& connect", default = true, enabled = false. Ok, start programming:

FMUD window:

FMUD defined section:

DIM BCONNECTED AS BOOLEAN

Connect menu:

IF not bconnected then

Fconnect.show 1

Mudsock.connect 'connected to MUD host

Bconnected = true

Mudin.setfocus

END IF

FMUD's LOAD event: bconnected = false

FMUD's Resize event:

Mudout.top = 0 'Adjusting the location of the control

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

MudSock's DataArrival event:

DIM STRDATA AS STRING

IF connection

Mudsock.getdata strdata 'Data from MudSock's buffer

Mudout.text = Mudout.text strdata

Mudout.Selstart = len (Mudout.Text)

If LEN (MUDOUT.TEXT)> 2000 TEN 'buffers 2000 words

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) 'gives the command line plus the carriage return

Fmud.mudsock.senddata s

For i = 1 to mudin.listcount

If Mudin.list (i) = mudin.text then

Mudin.RemoveItem (i) 'Deleting repetitive history commands

END IF

Next i

If Mudin.listCount> 30 TEN 'buffered 30 history commands

Mudin.removeItem 0

END IF

Mudin.additem mudin.text 'Add this item to the history of history

Mudin.selstart = 0

Mudin.sellength = len (mudin.text) 'This item command text is selected so that

'When you enter a command, you don't have to use it.

FConnect window:

Taddress and fport's Change event:

IF (Taddress.Text <> ") and (tport.text <>" ").

Cmdconnect.enabled = true

Else

Cmdconnect.enabled = false

END IF

Click event of the Connect button:

Fmud.muddsock.remotehost = taddress.text

Fmud.mudsock.remoteport = CINT (TPORT.TEXT)

Fconnect.hide

Ok, a MUD client service program is done, you can now connect to MUD. However, it is limited to the space, and now the function of this program is only the output information back, separate input and reuse historical commands, it is better than Telnet playing MUD. In addition, you must support the emphasis display function, just identify the ESCAPE '[' control string from the information string from the MUD host, and use the RichtextBox's SELCOLOR method to set the text color, which is why we use RichtextBox without general Reason for TextBox. Finally, it is pointed out that Winsock's Connect connection is correctly programmed in the Mudsock's OneROR event, and this program is slightly. If you are interested in MUD client programs or MUD, please visit the author Home: http://fanzhang.yeah.net

转载请注明原文地址:https://www.9cbs.com/read-3964.html

New Post(0)