server| Control Option Explicit
Public HostIP as String
Public Hostport as String
' Time of server startup
Dim StartTime as Date
' Number of players logged on to the server
Dim Visitnum as Integer
' Defines the maximum number of players that can be logged in
Const Maxconnect = 20
' Defines the number of Winsock controls that have been loaded
Dim Wsocknum as Integer
' defines an array that stores player information
Dim Muser (maxconnect) as UserInfo
' defines an array that stores chess information
Dim Mtwouser (MAXCONNECT/2) as Twouser
Private Sub tcpwsock_connectionrequest (ByVal RequestID as Long)
Dim I as Long
i = 1
Dim Free as Boolean
Free = False
' Wsocknum is the number of Winsock that are currently loaded
' Check for controls that are not linked in an array of already loaded controls
For i = 1 to Wsocknum
If Wsock (i). State = sckclosed Then
Free = True
Exit for
End If
Next I
' Maxconnect is the maximum number of connections, if the Winsock control has been loaded to the maximum, exit
If wsocknum = maxconnect and free = False Then
Exit Sub
End If
' If all the Winsock controls that are already loaded are connected, load the new control
If free = False Then
' Wsock (i) is an array of controls
Wsocknum = wsocknum + 1
Load Wsock (Wsocknum)
i = Wsocknum
End If
If Wsock (i). State <> sckclosed Then
Wsock (i). Close
End If
Wsock (i). Accept RequestID
Wsock (i). SendData, "/lgon, you're connected to the Busyants Gobang server."
' Save the player's station time, IP address
Muser (i) Mlogontime = Now ()
' Number of players logged on to the server +1
Visitnum = visitnum + 1
Muser (i). Muserip = Wsock (i). Remotehostip
Muser (i). mconnected = True
End Sub
Private Sub Txttalk_change ()
If Len (Txttalk.text) > 1000 Then
Txttalk.text = ""
End If
End Sub
Private Sub usercontrol_initialize ()
' Use Tcpwsock to listen for client requests
HostIP = Tcpwsock.localip
Tcpwsock.localport = 1001
Hostport = 1001
Tcpwsock.listen
Wsocknum = 1
Visitnum = 0
StartTime = Now ()
End Sub
Private Sub wsock_close (Index as Integer)
' Disconnected from the player's handling
Wsock (Index). Close
' Cleans up variables that hold player status
Muser (Index). Moppindex = 0
Muser (Index). mconnected = False
If Mtwouser (Muser (Index). Mindex). Fight = True Then
Mtwouser (Muser (Index). Mindex). Fight = False
' If the disconnected player is playing chess, the following procedure informs the opponent that he or she has exited the system.
If Mtwouser (Muser (index). Mindex). moppIndex1 = Index Then
Muser (Mtwouser (Muser (Index). Mindex). moppIndex2). Mindex = 0
Wsock (Mtwouser (Muser (Index). Mindex). MoppIndex2). SendData "/quit"
Else
Muser (Mtwouser (Muser (Index). Mindex). moppIndex1). Mindex = 0
Wsock (Mtwouser (Muser (Index). Mindex). MoppIndex1). SendData "/quit"
End If
Muser (Mtwouser (Muser (Index). Mindex). moppIndex1). Mindex = 0
End If
Muser (Index). Mindex = 0
Sendtoall Muser (Index). Nickname & "left the busyants Gobang system"
Txttalk.text = Txttalk.text & "(" & Time () & ")" & Muser (Index). Nickname & "Left Busyants Gobang system" & VB CrLf
End Sub
Private Sub Wsock_dataarrival (Index as Integer, ByVal bytestotal as Long)
Dim Information as String
Dim I as Integer
Dim TempStr as String
Dim Pos as Integer
Wsock (Index). GetData Information
Dim Header as String
Header = left$ (information, 5)
Select Case Header
Case "/call"
' Client call handling
Dim Callname as String
Callname = Mid (information, 6)
For i = 1 to Maxconnect
If Muser (i). Nickname = Callname and Muser (i). mconnected = True Then
Exit for
End If
Next
If i > Maxconnect Then
Wsock (Index). SendData "/play" & "No" & Index & "No this person!! "
&nb