|
本帖最后由 261869247 于 2010-4-2 13:02 编辑
刚才和你聊的问题
客户端#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("CS账号注册系统客户端", 319, 186, 350, 205)
$Button1 = GUICtrlCreateButton("CS英文ID", 24, 8, 81, 25)
$Button2 = GUICtrlCreateButton("CS中文ID", 24, 40, 81, 25)
$Button3 = GUICtrlCreateButton("你的密码", 24, 72, 81, 25)
$Button4 = GUICtrlCreateButton("确定注册", 72, 144, 81, 25)
$Input1 = GUICtrlCreateInput("", 120, 8, 121, 21)
$Input2 = GUICtrlCreateInput("", 120, 40, 121, 21)
$Input3 = GUICtrlCreateInput("", 120, 72, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Button5 = GUICtrlCreateButton("你的QQ", 24, 104, 81, 25)
$Input4 = GUICtrlCreateInput("", 120, 104, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
UDPStartup()
$socket = UDPOpen("127.0.0.1", 64213)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $Button4
$EN = GUICtrlRead($Input1)
$CN = GUICtrlRead($Input2)
$Pass = GUICtrlRead($Input3)
$QQ = GUICtrlRead($Input4)
UDPSend($socket,StringToBinary ('"' & "" & $en & '" "' & "" & $cn & '" "' & "" & $Pass & '" "' & "" & $QQ & '"',4));转换并发送二进制数据(支持中文全显示)
MsgBox(0,"服务器提示","注册成功")
EndSwitch
WEnd
服务端#include <GUIConstants.au3>
HotKeySet("!q","CLOSEClicked")
hotkeyset("!s","startbtn")
dim $socket = -1,$PS = True
$mainwindow = GUICreate("阳光网吧专用CS账号中文ID自助注册系统", 481, 440, 193, 121)
$text1 = GUICtrlCreateEdit("", 12, 12, 457, 384,0x0844 + 0x0008)
$startBtn = GUICtrlCreateButton("启动服务(ALT+&S)", 340, 405, 130, 25)
guictrlcreatelabel("启动服务 ALT+S,暂停服务 ALT+P,退出程序 ALT+Q",10,410)
GUISetState(@SW_SHOW)
pause()
Func pause()
if $socket <> -1 then UDPCloseSocket($socket)
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
CLOSEClicked()
Case $msg = $startBtn
startBtn()
EndSelect
WEnd
EndFunc
Func startbtn()
if $ps = True then
guictrlsetdata($startbtn,"暂停服务(ALT+&P)")
HotKeySet("!p","startbtn")
HotKeySet("!s")
$ps = not $ps
UDPs()
else
guictrlsetdata($startbtn,"启动服务(ALT+&S)")
$ps = not $ps
HotKeySet("!s","startbtn")
HotKeySet("!p")
pause()
endif
EndFunc
Func udps()
UDPStartup()
$socket = UDPBind("127.0.0.1", 64213)
If @error <> 0 Then Exit
While 1
$data = UDPRecv($socket, 1024,1);改动:接收数据调大一点,可以接收多一点数据,后面的1是强制以二进制方式接收
If $data <> "" Then
$data = BinaryToString ($data,4);增加:将二进制数据转换成字符
GUICtrlSetData($text1,$data & @CRLF & guictrlread($text1))
$file = FileOpen("reg.ini", 1)
FileWriteLine($file,$data)
EndIf
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
CLOSEClicked()
Case $msg = $startBtn
startBtn()
EndSelect
sleep(50)
WEnd
EndFunc
Func CLOSEClicked()
$ynexit = MsgBox(262196, "提示", "确定退出本程序吗?")
if $ynexit = 6 then
if $socket <> -1 then
UDPCloseSocket($socket)
UDPShutdown()
EndIf
Exit
EndIf
EndFunc
点了注册后 会按照客户端 固定的格式 发送到服务端
比如输入 玩家英文ID user
中文ID 玩家
你的密码 123
你的QQ 123
那么服务端获取数据并写入 123.ini 后的格式如下
"user" "玩家" "123" "123"
现在的问题是能把获取的数据分别写入多个cfg 文件吗? 比如
"user" "玩家" 这部分数据写入 1.cfg
"123" "123"这部分数据写入 2.cfg |
|