Нуждающийся
Регистрация: 12.11.2010
Адрес: Нашли чо спросить
Сообщений: 51
Написано 3 полезных сообщений (для 4 пользователей)
|
Помогите найти ошипко
Клиент:
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
Global stream=CreateUDPStream(448)
Global stream2=CreateUDPStream(49170)
Global cam
Global my_entity
Global my_ip
Global my_x#
Global my_y#
Global my_z#
Global server_order$
Global main_order#=-1
Global order$
Type player
Field entity
Field ip
Field command
Field class
Field weapon
Field x
Field y
Field z
Field pitch
Field yaw
Field roll
End Type
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\menu
Function Main_Menu()
Print "1.Myltiplayer"
Print "2.Exit"
main_menu_select#=Input("Press 1 or 2...")
Select main_menu_select
Case 1
Multiplayer_Menu()
Cls
Case 2
End
Default
End Select
End Function
Function Multiplayer_Menu()
Print "1.Join server"
Print "2.Exit"
multiplayer_menu_select#=Input("Press 1 or 2...")
Select multiplayer_menu_select
Case 1
join("127.0.0.1")
Cls
Case 2
End
Default
End Select
End Function
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\playter
Function Upd_my_player()
If KeyDown(200) MoveEntity my_entity,0,0,.1
If KeyDown(208) MoveEntity my_entity,0,0,-.1
If KeyDown(203) MoveEntity my_entity,-.1,0,0
If KeyDown(205) MoveEntity my_entity,.1,0,0
my_x#=EntityX(my_entity)
my_y#=EntityY(my_entity)
my_z#=EntityZ(my_entity)
End Function
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\i-met
Function Upd_network()
End Function
Function Join(ipadress$)
main_order#=0
order$="join..."
WriteLine stream,order$
WriteLine stream,my_ip
ip=Int_IP(ipadress$)
SendUDPMsg stream,ip,53424
If RecvUDPMsg(stream2) Then
map$=ReadLine$(stream2)
country$=ReadLine$(stream2)
If map$=True And country$=True Then Connect()
EndIf
End Function
Function Connect()
main_order#=1
order$="connecting..."
WriteLine stream,order$
WriteLine stream,my_ip
SendUDPMsg stream,ip,53424
order$="connecting end"
WriteLine stream,order$
If RecvUDPMsg(stream2) Then
server_order$=ReadLine$(stream2)
If server_order$="OK!" Then
Multiplayer_Game
EndIf
EndIf
End Function
Function Multiplayer_Game()
main_order#=2
user.player=New player
user\ip=GetMyIP()
user\entity=CreateCube()
my_entity=user\entity
my_ip=user\ip
cam=CreateCamera(my_entity)
PositionEntity cam,0,2,-5
End Function
Function Int_IP(IP$)
d1%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d2%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d3%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d4%=IP$
Return (d1 Shl 24) + (d2 Shl 16) + (d3 Shl 8 ) +d4
End Function
Function GetMyIP$()
Return DottedIP$(HostIP(CountHostIPs("")))
End Function
Main_Menu()
While KeyHit(1)=0
Select main_order#
Case 0
Join("127.0.0.1")
Case 1
Connect()
Case 2
Upd_my_player()
Text 100,100,""+my_x#+""+my_z#
Default
End Select
RenderWorld()
Flip
Wend
End
Сервер:
Global stream2=CreateUDPStream(49170)
Global map$
Global country$
Global status
Type Player
Field ip
Field command
Field class
Field weapon
Field x
Field y
Field z
Field pitch
Field yaw
Field roll
End Type
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\server
Function Create_Server()
map$=Input("Choose map...")
county$=Input("Choose country...")
End Function
Function UpdateNetwork()
If RecvUDPMsg(stream2) Then
order$=ReadLine$(stream2)
If order$="join..." Then
p.Player=New Player
p\ip=Int_IP(ReadLine$(stream2))
WriteLine stream,map$
WriteLine stream,country$
SendUDPMsg stream,p\ip,49170
ElseIf order="conecting..." Then
ElseIf order$="connecting end" Then
For p.player=Each player
status="OK!"
WriteLine stream,status
SendUDPMsg stream,p\ip,49170
Next
ElseIf order="game..." Then
For p.player=Each player
p\command=ReadFloat(stream2)
p\class=ReadFloat(stream2)
p\weapon=ReadFloat(stream2)
p\x=ReadFloat(stream2)
p\y=ReadFloat(stream2)
p\z=ReadFloat(stream2)
p\pitch=ReadFloat(stream2)
p\yaw=ReadFloat(stream2)
p\roll=ReadFloat(stream2)
Next
EndIf
EndIf
End Function
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\IP
Function Int_IP(IP$)
d1%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d2%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d3%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d4%=IP$
Return (d1 Shl 24) + (d2 Shl 16) + (d3 Shl 8 ) +d4
End Function
Create_Server()
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\WHILE
While Not KeyDown(1)
Cls
For p.Player=Each Player
Locate 5,5
Print DottedIP$(p\ip)
Next
UpdateNetwork()
Wend
При включеном сервере в клиенте(при включении) не создается stream.
|