Public ActAs As String
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpdefault As String, ByVal lpreturnedstring As String, ByVal nsize As Long, ByVal lpfilename As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpString As String, ByVal lpfilename As String) As Long
Public Cartejas1 As String
Public Cartejas2 As String
Public Cartejas3 As String
Public Cartejas4 As String
Public Cartejas5 As String
Public EneCar As String
Public ShouldNotPass As Boolean
Public ShouldClientNotPass As Boolean
Public Sub PutVar(File As String, Header As String, Var As String, Value As String)
Call WritePrivateProfileString(Header, Var, Value, File)
End Sub
Private Sub cOFF_Click()
TTGameOffline.Show
Me.Hide
End Sub
Private Function GetVar(File As String, Header As String, Var As String) As String
Dim sSpaces As String ' Max string length
Dim szReturn As String ' Return default value if not found
szReturn = vbNullString
sSpaces = Space$(1000)
Call GetPrivateProfileString(Header, Var, szReturn, sSpaces, Len(sSpaces), File)
GetVar = RTrim$(sSpaces)
GetVar = Left(GetVar, Len(GetVar) - 1)
End Function
Private Sub Connect_Click()
If ActAs = "Serve" Then Exit Sub
Winsock1.Close
Winsock1.RemoteHost = txtIP.Text
Winsock1.RemotePort = txtPORT.Text
Winsock1.Connect
ActAs = "Client"
txtIP.Text = "Found match!"
End Sub
Private Sub CServ_Click()
If ActAs = "Client" Then Exit Sub
Winsock1.Close
ActAs = "Serve"
Winsock1.LocalPort = txtPORT.Text
Winsock1.Listen
txtIP.Text = "Waiting for a rival . . ."
End Sub
Private Sub Dissc_Click()
Winsock1.Close
End
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
ShallNotPass = True
Winsock1.Accept requestID
Dim nombrejugador As String
nombrejugador = TTGameOnline.GetVar(App.Path & "player.ini", "PLAYER", "Name")
TTGameOnline.CHATwin.SelStart = Len(TTGameOnline.CHATwin.Text)
TTGameOnline.CHATwin.Text = TTGameOnline.CHATwin.Text & nombrejugador & " Is acting as SERVER!" & vbCrLf
TTGameOnline.CHATwin.SelStart = Len(TTGameOnline.CHATwin.Text)
Winsock1.SendData "1" & nombrejugador & " Is acting as SERVER!" & vbCrLf
'Cartejas1 = GetVar(App.Path & "player.ini", "PLAYER", "Card1")
'Cartejas2 = GetVar(App.Path & "player.ini", "PLAYER", "Card2")
'Cartejas3 = GetVar(App.Path & "player.ini", "PLAYER", "Card3")
'Cartejas4 = GetVar(App.Path & "player.ini", "PLAYER", "Card4")
'Cartejas5 = GetVar(App.Path & "player.ini", "PLAYER", "Card5")
Debug.Print Cartejas1
Winsock1.SendData "_"
txtIP.Text = "Found match!"
End Sub
Public Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
MsgBox "Lost connection with game partner. Error:" & Number
TTGameOnline.Hide
MultiplayForm.Show
End Sub
Public Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Buffer As String
Winsock1.GetData Buffer
If Left(Buffer, 1) = "1" Then
Buffer = Mid(Buffer, 2, Len(Buffer))
TTGameOnline.CHATwin.Text = TTGameOnline.CHATwin & Buffer & vbCrLf
End If
If Left(Buffer, 1) = "z" Then
MsgBox "The game partner has left the session."
MultiplayForm.Winsock1.Close
Me.Show
TTGameOnline.Hide
End If
Cartejas1 = GetVar(App.Path & "player.ini", "PLAYER", "Card1")
Cartejas2 = GetVar(App.Path & "player.ini", "PLAYER", "Card2")
Cartejas3 = GetVar(App.Path & "player.ini", "PLAYER", "Card3")
Cartejas4 = GetVar(App.Path & "player.ini", "PLAYER", "Card4")
Cartejas5 = GetVar(App.Path & "player.ini", "PLAYER", "Card5")
If Left(Buffer, 1) = "C" Then
' If ShouldClientNotPass = True Then Exit Sub
' If Left(Buffer, 2) = "Y" Then ShallNotPass = False
' If ShallNotPass = True Then Exit Sub
If ActAs = "Serve" Then
' ShouldClientNotPass = True
Winsock1.SendData "CN" & Cartejas1 & Cartejas2 & Cartejas3 & Cartejas4 & Cartejas5
End If
'For i = 1 To 5
' EneDCards(i) = CInt(Left(Buffer, i + 1))
'Next i
' Dim i As Integer
' Dim doomstring(1 To 5) As String
' For i = 1 To 5
' doomstring(i) = Left(Buffer, 2 + i)
' Debug.Print doomstring(i); v
' Next i
EneCar = Left(Buffer, 3)
Call PutVar(App.Path & "player.ini", "PLAYER2", "Card1", EneCar)
EneCar = Left(Buffer, 4)
Call PutVar(App.Path & "player.ini", "PLAYER2", "Card2", EneCar)
EneCar = Left(Buffer, 5)
Call PutVar(App.Path & "player.ini", "PLAYER2", "Card3", EneCar)
EneCar = Left(Buffer, 6)
Call PutVar(App.Path & "player.ini", "PLAYER2", "Card4", EneCar)
EneCar = Left(Buffer, 7)
Call PutVar(App.Path & "player.ini", "PLAYER2", "Card5", EneCar)
TTGameOnline.Show
Me.Hide
End If
If Left(Buffer, 1) = "_" Then
Winsock1.SendData "CY" & Cartejas1 & Catejas2 & Catejas3 & Catejas4 & Catejas5
End If
End Sub