Home

Add

Edit

Without Linenumbers

Code in Textfield

Download

  1. '##############################################################################################################
    
  2. '##############################################################################################################
    
  3. ' TSNEplay_V3 - TCP Socket Networking [Eventing] Play (Gaming Extension) Version: 1.0 for TSNE_V3
    
  4. '##############################################################################################################
    
  5. '##############################################################################################################
    
  6. ' 2009 By.: /_\ DeltaLab's Germany - Experimental Computing
    
  7. ' Autor: Martin Wiemann
    
  8. '##############################################################################################################
    
  9. 
    
  10. 
    
  11. 
    
  12. 
    
  13. 
    
  14. #IFNDEF _TSNEplay_
    
  15.     #DEFINE _TSNEplay_
    
  16. '>...
    
  17. 
    
  18. '##############################################################################################################
    
  19. #DEFINE TSNE_DEF_REUSER
    
  20. #INCLUDE Once "TSNE_V3.bi"
    
  21. 
    
  22. 
    
  23. 
    
  24. '##############################################################################################################
    
  25. Enum TSNEPlay_GURUCode
    
  26.     TSNEPlay_NoError                            = 1
    
  27.     TSNEPlay_Unknown                            = 0
    
  28.     TSNEPlay_NotReadyForNewConnection           = -1000
    
  29.     TSNEPlay_PlayerIDNotFound                   = -1001
    
  30.     TSNEPlay_MessageToLong                      = -1002
    
  31. End Enum
    
  32. 
    
  33. 
    
  34. 
    
  35. '##############################################################################################################
    
  36. Enum TSNEPlay_State_Enum
    
  37.     TSNEPlay_State_Unknown                      = 0
    
  38.     TSNEPlay_State_Disconnected                 = 1
    
  39.     TSNEPlay_State_Connecting                   = 2
    
  40.     TSNEPlay_State_Connected                    = 3
    
  41.     TSNEPlay_State_Login                        = 4
    
  42.     TSNEPlay_State_Ready                        = 5
    
  43. End Enum
    
  44. 
    
  45. '--------------------------------------------------------------------------------------------------------------
    
  46. Enum TSNEPlay_MessageType_Enum
    
  47.     TSNEPlay_MSGType_Regular                    = 0
    
  48.     TSNEPlay_MSGType_Private                    = 1
    
  49.     TSNEPlay_MSGType_Notice                     = 2
    
  50.     TSNEPlay_MSGType_Hightlighted               = 3
    
  51. End Enum
    
  52. 
    
  53. 
    
  54. 
    
  55. '##############################################################################################################
    
  56. Enum TSNEPlay_INT_CMDType_Enum
    
  57.     TSNEPlay_INT_MSGT_Unknown                   = 0
    
  58.     TSNEPlay_INT_MSGT_NeedPassword              = 1
    
  59.     TSNEPlay_INT_MSGT_Password                  = 2
    
  60.     TSNEPlay_INT_MSGT_PasswordWrong             = 3
    
  61.     TSNEPlay_INT_MSGT_GetInfo                   = 4
    
  62.     TSNEPlay_INT_MSGT_PutInfo                   = 5
    
  63.     TSNEPlay_INT_MSGT_Ready                     = 10
    
  64.     TSNEPlay_INT_MSGT_StreamError               = 999999
    
  65.     TSNEPlay_INT_MSGT_Ping                      = 1000
    
  66.     TSNEPlay_INT_MSGT_Pong                      = 1001
    
  67.     TSNEPlay_INT_MSGT_MSG                       = 1002
    
  68.     TSNEPlay_INT_MSGT_Move                      = 1003
    
  69.     TSNEPlay_INT_MSGT_Dat                       = 1004
    
  70.     TSNEPlay_INT_MSGT_Con                       = 1005
    
  71.     TSNEPlay_INT_MSGT_Dis                       = 1006
    
  72.     TSNEPlay_INT_MSGT_Full                      = 1007
    
  73. End Enum
    
  74. 
    
  75. 
    
  76. 
    
  77. '##############################################################################################################
    
  78. Type TSNEPlay_INT_CommandQue_Type
    
  79.     V_Next                                          As TSNEPlay_INT_CommandQue_Type Ptr
    
  80.     V_Prev                                          As TSNEPlay_INT_CommandQue_Type Ptr
    
  81.     
    
  82.     V_RAW                                           As String
    
  83.     V_CMDType                                       As TSNEPlay_INT_CMDType_Enum
    
  84.     V_Data                                          As String
    
  85. End Type
    
  86. 
    
  87. 
    
  88. 
    
  89. '##############################################################################################################
    
  90. Type TSNEPlay_INT_Client_Type
    
  91.     V_Next                                          As TSNEPlay_INT_Client_Type Ptr
    
  92.     V_Prev                                          As TSNEPlay_INT_Client_Type Ptr
    
  93.     
    
  94.     V_TSNEID                                        As Uinteger
    
  95.     V_IPA                                           As String
    
  96.     V_Data                                          As String
    
  97.     V_State                                         As TSNEPlay_State_Enum
    
  98.     
    
  99.     V_CMDQueF                                       As TSNEPlay_INT_CommandQue_Type Ptr
    
  100.     V_CMDQueL                                       As TSNEPlay_INT_CommandQue_Type Ptr
    
  101.     V_CMDQueC                                       As Ushort
    
  102.     
    
  103.     V_PlayerID                                      As Uinteger
    
  104.     V_Nickname                                      As String
    
  105.     
    
  106.     T_LastPing                                      As Double
    
  107.     T_PingT                                         As Double
    
  108. End Type
    
  109. 
    
  110. '--------------------------------------------------------------------------------------------------------------
    
  111. Dim Shared TSNEPlay_INT_ClientF                     As TSNEPlay_INT_Client_Type Ptr
    
  112. Dim Shared TSNEPlay_INT_ClientL                     As TSNEPlay_INT_Client_Type Ptr
    
  113. Dim Shared TSNEPlay_INT_ClientC                     As Uinteger
    
  114. Dim Shared TSNEPlay_INT_PlayerIDC                   As Uinteger
    
  115. 
    
  116. 
    
  117. 
    
  118. '##############################################################################################################
    
  119. Dim Shared TSNEPlay_INT_Mutex                       As Any Ptr
    
  120. '--------------------------------------------------------------------------------------------------------------
    
  121. Dim Shared TSNEPlay_INT_State                       As TSNEPlay_State_Enum
    
  122. Dim Shared TSNEPlay_INT_ClientMode                  As Ubyte
    
  123. Dim Shared TSNEPlay_INT_ServerPassword              As String
    
  124. Dim Shared TSNEPlay_INT_Nickname                    As String
    
  125. '--------------------------------------------------------------------------------------------------------------
    
  126. Dim Shared TSNEPlay_INT_Server_TSNEID               As Uinteger
    
  127. Dim Shared TSNEPlay_INT_Server_PlayerID             As Uinteger
    
  128. Dim Shared TSNEPlay_INT_Server_MaxPlayer            As Ushort
    
  129. '--------------------------------------------------------------------------------------------------------------
    
  130. Dim Shared TSNEPlay_INT_Client_TSNEID               As Uinteger
    
  131. Dim Shared TSNEPlay_INT_Client_Data                 As String
    
  132. Dim Shared TSNEPlay_INT_Client_PlayerID             As Uinteger
    
  133. '--------------------------------------------------------------------------------------------------------------
    
  134. Dim Shared TSNEPlay_INT_Event_ConnectionState       As Sub (Byval V_FromPlayerID As Uinteger, Byval V_State As TSNEPlay_State_Enum)
    
  135. Dim Shared TSNEPlay_INT_Event_Player_Connected      As Sub (Byval V_PlayerID As Uinteger, V_IPA As String, V_Nickname As String)
    
  136. Dim Shared TSNEPlay_INT_Event_Player_Disconnected   As Sub (Byval V_PlayerID As Uinteger)
    
  137. Dim Shared TSNEPlay_INT_Event_Message               As Sub (Byval V_FromPlayerID As Uinteger, Byval V_ToPlayerID As Uinteger, Byval V_Message As String, Byval V_MessageType As TSNEPlay_MessageType_Enum)
    
  138. Dim Shared TSNEPlay_INT_Event_Move                  As Sub (Byval V_FromPlayerID As Uinteger, Byval V_ToPlayerID As Uinteger, Byval V_NewPositionX As Double, Byval V_NewPositionY As Double, Byval V_NewPositionZ As Double, Byval V_SubData As Uinteger)
    
  139. Dim Shared TSNEPlay_INT_Event_Data                  As Sub (Byval V_FromPlayerID As Uinteger, Byval V_ToPlayerID As Uinteger, Byref V_Data As String)
    
  140. 
    
  141. 
    
  142. 
    
  143. '##############################################################################################################
    
  144. Sub TSNEPlay_INT_Construct() Constructor
    
  145. TSNEPlay_INT_Mutex = Mutexcreate()
    
  146. End Sub
    
  147. 
    
  148. '--------------------------------------------------------------------------------------------------------------
    
  149. Sub TSNEPlay_INT_Destruct() Destructor
    
  150. Mutexdestroy(TSNEPlay_INT_Mutex)
    
  151. TSNEPlay_INT_Mutex = 0
    
  152. End Sub
    
  153. 
    
  154. 
    
  155. 
    
  156. '##############################################################################################################
    
  157. Function TSNEPlay_INT_ClientGetPID(V_PlayerID As Uinteger) As TSNEPlay_INT_Client_Type Ptr
    
  158. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientF
    
  159. Do Until TPtr = 0
    
  160.     If TPtr->V_PlayerID = V_PlayerID Then Return TPtr
    
  161.     TPtr = TPtr->V_Next
    
  162. Loop
    
  163. Return 0
    
  164. End Function
    
  165. 
    
  166. '--------------------------------------------------------------------------------------------------------------
    
  167. Function TSNEPlay_INT_ClientGetTSNEID(V_TSNEID As Uinteger) As TSNEPlay_INT_Client_Type Ptr
    
  168. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientF
    
  169. Do Until TPtr = 0
    
  170.     If TPtr->V_TSNEID = V_TSNEID Then Return TPtr
    
  171.     TPtr = TPtr->V_Next
    
  172. Loop
    
  173. Return 0
    
  174. End Function
    
  175. 
    
  176. '--------------------------------------------------------------------------------------------------------------
    
  177. Function TSNEPlay_INT_ClientAdd() As TSNEPlay_INT_Client_Type Ptr
    
  178. Dim TPtr As TSNEPlay_INT_Client_Type Ptr
    
  179. TSNEPlay_INT_PlayerIDC += 1
    
  180. Do Until TSNEPlay_INT_ClientGetPID(TSNEPlay_INT_PlayerIDC) = 0
    
  181.     TSNEPlay_INT_PlayerIDC += 1
    
  182.     If TSNEPlay_INT_PlayerIDC = 0 Then TSNEPlay_INT_PlayerIDC = 1
    
  183. Loop
    
  184. If TSNEPlay_INT_ClientL <> 0 Then
    
  185.     TSNEPlay_INT_ClientL->V_Next = Callocate(Sizeof(TSNEPlay_INT_Client_Type))
    
  186.     TSNEPlay_INT_ClientL->V_Next->V_Prev = TSNEPlay_INT_ClientL
    
  187.     TSNEPlay_INT_ClientL = TSNEPlay_INT_ClientL->V_Next
    
  188. Else
    
  189.     TSNEPlay_INT_ClientL = Callocate(Sizeof(TSNEPlay_INT_Client_Type))
    
  190.     TSNEPlay_INT_ClientF = TSNEPlay_INT_ClientL
    
  191. End If
    
  192. With *TSNEPlay_INT_ClientL
    
  193.     .V_PlayerID = TSNEPlay_INT_PlayerIDC
    
  194. End With
    
  195. TSNEPlay_INT_ClientC += 1
    
  196. Return TSNEPlay_INT_ClientL
    
  197. End Function
    
  198. 
    
  199. '--------------------------------------------------------------------------------------------------------------
    
  200. Sub TSNEPlay_INT_ClientDel(V_Client As TSNEPlay_INT_Client_Type Ptr)
    
  201. If V_Client->V_Next <> 0 Then V_Client->V_Next->V_Prev = V_Client->V_Prev
    
  202. If V_Client->V_Prev <> 0 Then V_Client->V_Prev->V_Next = V_Client->V_Next
    
  203. If TSNEPlay_INT_ClientF = V_Client Then TSNEPlay_INT_ClientF = V_Client->V_Next
    
  204. If TSNEPlay_INT_ClientL = V_Client Then TSNEPlay_INT_ClientL = V_Client->V_Prev
    
  205. With *V_Client
    
  206.     Do Until .V_CMDQueF = 0
    
  207.         .V_CMDQueL = .V_CMDQueF->V_Next
    
  208.         Deallocate(.V_CMDQueF)
    
  209.         .V_CMDQueF = .V_CMDQueL
    
  210.     Loop
    
  211. End With
    
  212. Deallocate(V_Client)
    
  213. If TSNEPlay_INT_ClientC > 0 Then TSNEPlay_INT_ClientC -= 1
    
  214. End Sub
    
  215. 
    
  216. 
    
  217. 
    
  218. '##############################################################################################################
    
  219. Function TSNEPlay_Desc_GetGuruCode(V_GuruCode As TSNEPlay_GURUCode) As String
    
  220. Select Case V_GuruCode
    
  221.     Case TSNEPlay_NoError                           : Return "No error!"
    
  222.     Case TSNEPlay_Unknown                           : Return "Unknown error!"
    
  223.     Case TSNEPlay_NotReadyForNewConnection          : Return "Not Ready! Conection Already Exist! Close all connections!"
    
  224.     Case TSNEPlay_MessageToLong                     : Return "Message text is too long!"
    
  225.     Case Else                                       : Return TSNE_GetGURUCode(V_GuruCode)
    
  226. End Select
    
  227. End Function
    
  228. 
    
  229. '--------------------------------------------------------------------------------------------------------------
    
  230. Function TSNEPlay_Desc_GetStateCode(V_State As TSNEPlay_State_Enum) As String
    
  231. Select Case V_State
    
  232.     Case TSNEPlay_State_Unknown                     : Return "Unknown"
    
  233.     Case TSNEPlay_State_Disconnected                : Return "Disconnected!"
    
  234.     Case TSNEPlay_State_Connecting                  : Return "Connecting..."
    
  235.     Case TSNEPlay_State_Connected                   : Return "Connected!"
    
  236.     Case TSNEPlay_State_Login                       : Return "Login..."
    
  237.     Case TSNEPlay_State_Ready                       : Return "Ready!"
    
  238.     Case Else                                       : Return "[Unknown State-Code]"
    
  239. End Select
    
  240. End Function
    
  241. 
    
  242. 
    
  243. 
    
  244. '##############################################################################################################
    
  245. Function TSNEPlay_INT_CreateStreamCommand(V_Command As TSNEPlay_INT_CMDType_Enum, V_Data As String = "") As String
    
  246. 'Print "OUT_CMD: >"; Str(V_Command); "<___>"; Str(Len(V_Data)) & "<"
    
  247. Dim MX As Uinteger = 4 + Len(V_Data)
    
  248. Dim T As String
    
  249. T += Chr((MX Shr 24) And 255) & Chr((MX Shr 16) And 255) & Chr((MX Shr 8) And 255) & Chr(MX And 255)
    
  250. T += Chr((V_Command Shr 24) And 255) & Chr((V_Command Shr 16) And 255) & Chr((V_Command Shr 8) And 255) & Chr(V_Command And 255)
    
  251. Return T & V_Data
    
  252. End Function
    
  253. 
    
  254. '--------------------------------------------------------------------------------------------------------------
    
  255. Sub TSNEPlay_INT_ParseStreamCommand(Byref V_Data As String, Byref R_CMDQueF As TSNEPlay_INT_CommandQue_Type Ptr, Byref R_CMDQueL As TSNEPlay_INT_CommandQue_Type Ptr)
    
  256. Dim MX As Uinteger
    
  257. Dim XRAW As String
    
  258. Dim XCMD As TSNEPlay_INT_CMDType_Enum
    
  259. Dim XData As String
    
  260. Do
    
  261.     If Len(V_Data) < 8 Then Exit Sub
    
  262.     MX = (V_Data[0] Shl 24) Or (V_Data[1] Shl 16) Or (V_Data[2] Shl 8) Or V_Data[3]
    
  263.     If (Len(V_Data) - 4) < MX Then Exit Sub
    
  264.     XCMD = (V_Data[4] Shl 24) Or (V_Data[5] Shl 16) Or (V_Data[6] Shl 8) Or V_Data[7]
    
  265.     XRAW = Left(V_Data, MX + 4)
    
  266.     XData = Mid(V_Data, 9, MX - 4)
    
  267.     V_Data = Mid(V_Data, MX + 5)
    
  268.     If R_CMDQueL <> 0 Then
    
  269.         R_CMDQueL->V_Next = Callocate(Sizeof(TSNEPlay_INT_CommandQue_Type))
    
  270.         R_CMDQueL = R_CMDQueL->V_Next
    
  271.     Else
    
  272.         R_CMDQueL = Callocate(Sizeof(TSNEPlay_INT_CommandQue_Type))
    
  273.         R_CMDQueF = R_CMDQueL
    
  274.     End If
    
  275.     With *R_CMDQueL
    
  276.         .V_RAW = XRAW
    
  277.         .V_CMDType = XCMD
    
  278.         .V_Data = XData
    
  279.     End With
    
  280. Loop
    
  281. End Sub
    
  282. 
    
  283. '--------------------------------------------------------------------------------------------------------------
    
  284. Function TSNEPlay_INT_SendData(V_ToPlayerID As Uinteger, V_Data As String, Byref R_LocalSend As Ubyte) As TSNEPlay_GURUCode
    
  285. 'Print "OUT:"; V_ToPlayerID; " "; Len(V_Data); "  ";: For XXX as UInteger = 1 to Len(V_Data): Print V_Data[XXX - 1]; " ";: Next: Print
    
  286. R_LocalSend = 0
    
  287. If TSNEPlay_INT_ClientMode = 1 Then
    
  288.     TSNE_Data_Send(TSNEPlay_INT_Client_TSNEID, V_Data)
    
  289.     Return TSNEPlay_NoError
    
  290. End If
    
  291. Dim TPtr As TSNEPlay_INT_Client_Type Ptr
    
  292. Mutexlock(TSNEPlay_INT_Mutex)
    
  293. If V_ToPlayerID > 0 Then
    
  294.     Dim TSID As Uinteger
    
  295.     TPtr = TSNEPlay_INT_ClientGetPID(V_ToPlayerID)
    
  296.     If TPtr = 0 Then Mutexunlock(TSNEPlay_INT_Mutex): Return TSNEPlay_PlayerIDNotFound
    
  297.     TSID = TPtr->V_TSNEID
    
  298.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  299.     If TSID > 0 Then
    
  300.         TSNE_Data_Send(TSID, V_Data)
    
  301.     Else: R_LocalSend = 1
    
  302.     End If
    
  303. Else
    
  304.     Dim DD() As Uinteger
    
  305.     Dim DC As Uinteger
    
  306.     Dim DX As Uinteger
    
  307.     TPtr = TSNEPlay_INT_ClientF
    
  308.     Do Until TPtr = 0
    
  309.         If TPtr->V_State = TSNEPlay_State_Ready Then
    
  310.             If TPtr->V_TSNEID > 0 Then
    
  311.                 DC += 1
    
  312.                 If DC > DX Then
    
  313.                     DX += 4
    
  314.                     Redim Preserve DD(DX) As Uinteger
    
  315.                 End If
    
  316.                 DD(DC) = TPtr->V_TSNEID
    
  317.             Else: R_LocalSend = 1
    
  318.             End If
    
  319.         End If
    
  320.         TPtr = TPtr->V_Next
    
  321.     Loop
    
  322.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  323.     For X As Uinteger = 1 To DC
    
  324.         TSNE_Data_Send(DD(X), V_Data)
    
  325.     Next
    
  326. End If
    
  327. Return TSNEPlay_NoError
    
  328. End Function
    
  329. 
    
  330. 
    
  331. 
    
  332. '##############################################################################################################
    
  333. Sub TSNEPlay_INT_SendPlayerTable(V_TSNEID As Uinteger)
    
  334. Dim D As String
    
  335. Dim TMS0 As String
    
  336. Dim TMS1 As String
    
  337. Dim TMV0 As Uinteger
    
  338. Mutexlock(TSNEPlay_INT_Mutex)
    
  339. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientF
    
  340. Do Until TPtr = 0
    
  341.     If TPtr->V_TSNEID <> V_TSNEID Then
    
  342.         With *TPtr
    
  343.             TMS1 = Chr((.V_PlayerID Shr 24) And 255) & Chr((.V_PlayerID Shr 16) And 255) & Chr((.V_PlayerID Shr 8) And 255) & Chr(.V_PlayerID And 255)
    
  344.             TMV0 = 0: TMS1 += Chr((TMV0 Shr 24) And 255) & Chr((TMV0 Shr 16) And 255) & Chr((TMV0 Shr 8) And 255) & Chr(TMV0 And 255)
    
  345.             TMS1 += ""
    
  346.             TMV0 = Len(.V_Nickname): TMS1 += Chr((TMV0 Shr 24) And 255) & Chr((TMV0 Shr 16) And 255) & Chr((TMV0 Shr 8) And 255) & Chr(TMV0 And 255)
    
  347.             TMS1 += .V_Nickname
    
  348.             TMS1 = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Con, TMS1)
    
  349.             D += TMS1
    
  350.         End With
    
  351.     End If
    
  352.     TPtr = TPtr->V_Next
    
  353. Loop
    
  354. Mutexunlock(TSNEPlay_INT_Mutex)
    
  355. TSNE_Data_Send(V_TSNEID, D)
    
  356. End Sub
    
  357. 
    
  358. 
    
  359. 
    
  360. '##############################################################################################################
    
  361. Sub TSNEPlay_INT_Disconnected(Byval V_TSNEID As Uinteger)
    
  362. 'Print "DIS:"; V_TSNEID
    
  363. If TSNEPlay_INT_ClientMode = 1 Then
    
  364.     TSNEPlay_INT_State = TSNEPlay_State_Disconnected
    
  365.     If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  366.     Exit Sub
    
  367. End If
    
  368. Mutexlock(TSNEPlay_INT_Mutex)
    
  369. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientGetTSNEID(V_TSNEID)
    
  370. If TPtr = 0 Then Mutexunlock(TSNEPlay_INT_Mutex): TSNE_Disconnect(V_TSNEID): Exit Sub
    
  371. Dim TPID As Uinteger = TPtr->V_PlayerID
    
  372. Dim TAOK As TSNEPlay_State_Enum = TPtr->V_State
    
  373. TSNEPlay_INT_ClientDel(TPtr)
    
  374. Mutexunlock(TSNEPlay_INT_Mutex)
    
  375. If TSNEPlay_INT_Event_Player_Disconnected <> 0 Then TSNEPlay_INT_Event_Player_Disconnected(TPID)
    
  376. If TAOK <> TSNEPlay_State_Ready Then Exit Sub
    
  377. Dim T As String = Chr((TPID Shr 24) And 255) & Chr((TPID Shr 16) And 255) & Chr((TPID Shr 8) And 255) & Chr(TPID And 255)
    
  378. T = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Dis, T)
    
  379. Dim TLocalSend As Ubyte
    
  380. Dim RV As TSNEPlay_GURUCode = TSNEPlay_INT_SendData(0, T, TLocalSend)
    
  381. End Sub
    
  382. 
    
  383. '--------------------------------------------------------------------------------------------------------------
    
  384. Sub TSNEPlay_INT_Connected(Byval V_TSNEID As Uinteger)
    
  385. 'Print "CON:"; V_TSNEID
    
  386. If TSNEPlay_INT_ClientMode = 1 Then
    
  387.     TSNEPlay_INT_State = TSNEPlay_State_Connected
    
  388.     If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  389.     Exit Sub
    
  390. End If
    
  391. Mutexlock(TSNEPlay_INT_Mutex)
    
  392. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientGetTSNEID(V_TSNEID)
    
  393. If TPtr = 0 Then Mutexunlock(TSNEPlay_INT_Mutex): TSNE_Disconnect(V_TSNEID): Exit Sub
    
  394. Dim TPID As Uinteger
    
  395. With *TPtr
    
  396.     If TSNEPlay_INT_ServerPassword = "" Then
    
  397.         .V_State        = TSNEPlay_State_Connected
    
  398.     Else: .V_State      = TSNEPlay_State_Login
    
  399.     End If
    
  400.     TPID = .V_PlayerID
    
  401. End With
    
  402. Mutexunlock(TSNEPlay_INT_Mutex)
    
  403. If TSNEPlay_INT_ServerPassword <> "" Then
    
  404.     TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_NeedPassword))
    
  405. Else: TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_GetInfo, Str(TPID)))
    
  406. End If
    
  407. End Sub
    
  408. 
    
  409. '--------------------------------------------------------------------------------------------------------------
    
  410. Sub TSNEPlay_INT_NewData(Byval V_TSNEID As Uinteger, Byref V_Data As String)
    
  411. 'Print "DAT:"; V_TSNEID; " "; Len(V_Data); "  ";: For XXX as UInteger = 1 to Len(V_Data): Print V_Data[XXX - 1]; " ";: Next: Print
    
  412. Dim TCMDQueF As TSNEPlay_INT_CommandQue_Type Ptr
    
  413. Dim TCMDQueL As TSNEPlay_INT_CommandQue_Type Ptr
    
  414. Dim TCInfo As TSNEPlay_INT_Client_Type
    
  415. Dim TPtr As TSNEPlay_INT_Client_Type Ptr
    
  416. If TSNEPlay_INT_ClientMode = 1 Then
    
  417.     If Len(TSNEPlay_INT_Client_Data) > 10000 Then
    
  418.         TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_StreamError))
    
  419.         TSNE_Disconnect(V_TSNEID)
    
  420.         Exit Sub
    
  421.     End If
    
  422.     TSNEPlay_INT_Client_Data += V_Data
    
  423.     TSNEPlay_INT_ParseStreamCommand(TSNEPlay_INT_Client_Data, TCMDQueF, TCMDQueL)
    
  424. Else
    
  425.     Mutexlock(TSNEPlay_INT_Mutex)
    
  426.     TPtr = TSNEPlay_INT_ClientGetTSNEID(V_TSNEID)
    
  427.     If TPtr = 0 Then Mutexunlock(TSNEPlay_INT_Mutex): TSNE_Disconnect(V_TSNEID): Exit Sub
    
  428.     Dim TData As String = TPtr->V_Data & V_Data
    
  429.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  430.     If Len(TData) > 10000 Then
    
  431.         TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_StreamError))
    
  432.         TSNE_Disconnect(V_TSNEID)
    
  433.         Exit Sub
    
  434.     End If
    
  435.     TSNEPlay_INT_ParseStreamCommand(TData, TCMDQueF, TCMDQueL)
    
  436.     Mutexlock(TSNEPlay_INT_Mutex)
    
  437.     TPtr = TSNEPlay_INT_ClientGetTSNEID(V_TSNEID)
    
  438.     If TPtr = 0 Then Mutexunlock(TSNEPlay_INT_Mutex): TSNE_Disconnect(V_TSNEID): Exit Sub
    
  439.     TPtr->V_Data = TData
    
  440.     TCInfo = *TPtr
    
  441.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  442. End If
    
  443. Dim TLocalSend As Ubyte
    
  444. Dim RV As TSNEPlay_GURUCode
    
  445. Dim XErrExit As Ubyte
    
  446. Dim TMV0 As Uinteger
    
  447. Dim TMV1 As Uinteger
    
  448. Dim TMV2 As Double
    
  449. Dim TMV3 As Double
    
  450. Dim TMV4 As Double
    
  451. Dim TMV5 As Uinteger
    
  452. Dim TMV6 As Uinteger
    
  453. Dim TMV7 As Uinteger
    
  454. Dim TMS0 As String
    
  455. Dim TMS1 As String
    
  456. Do Until TCMDQueF = 0
    
  457.     TCMDQueL = TCMDQueF->V_Next
    
  458.     If XErrExit = 0 Then
    
  459.         With *TCMDQueF
    
  460.             TMV0 = 0
    
  461.             TMV1 = 0
    
  462.             TMV2 = 0
    
  463.             TMV3 = 0
    
  464.             TMV4 = 0
    
  465.             TMV5 = 0
    
  466.             TMS0 = ""
    
  467.             TMS1 = ""
    
  468. '           Print "CMD: >"; Str(.V_CMDType); "<___>"; .V_Data; "<"
    
  469. '           Print "IN_CMD: >"; Str(.V_CMDType); "<___>"; Str(Len(.V_Data)); "<"
    
  470.             If TSNEPlay_INT_ClientMode = 1 Then
    
  471.                 Select Case .V_CMDType
    
  472.                     Case TSNEPlay_INT_MSGT_Unknown
    
  473.                     
    
  474.                     Case TSNEPlay_INT_MSGT_Full
    
  475.                         
    
  476.                     Case TSNEPlay_INT_MSGT_NeedPassword
    
  477.                         If TSNEPlay_INT_State = TSNEPlay_State_Connected Then
    
  478.                             TSNEPlay_INT_State = TSNEPlay_State_Login
    
  479.                             If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  480.                             TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Password, TSNEPlay_INT_ServerPassword))
    
  481.                         End If
    
  482.                         
    
  483.                     Case TSNEPlay_INT_MSGT_PasswordWrong
    
  484.                         XErrExit = 1
    
  485.                         
    
  486.                     Case TSNEPlay_INT_MSGT_GetInfo
    
  487.                         TSNEPlay_INT_Client_PlayerID = Valuint(.V_Data)
    
  488.                         TMV0 = Len(TSNEPlay_INT_Nickname): TMS0 += Chr((TMV0 Shr 24) And 255) & Chr((TMV0 Shr 16) And 255) & Chr((TMV0 Shr 8) And 255) & Chr(TMV0 And 255)
    
  489.                         TMS0 += TSNEPlay_INT_Nickname
    
  490.                         TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_PutInfo, TMS0))
    
  491.                         
    
  492.                     Case TSNEPlay_INT_MSGT_PutInfo
    
  493.                         
    
  494.                     Case TSNEPlay_INT_MSGT_Ready
    
  495.                         TSNEPlay_INT_State = TSNEPlay_State_Ready
    
  496.                         If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  497.                         
    
  498.                     Case TSNEPlay_INT_MSGT_StreamError
    
  499.                         XErrExit = 1
    
  500.                         
    
  501.                     Case TSNEPlay_INT_MSGT_Ping
    
  502.                         
    
  503.                     Case TSNEPlay_INT_MSGT_MSG
    
  504.                         If TSNEPlay_INT_Event_Message <> 0 Then
    
  505.                             If Len(.V_Data) >= 16 Then
    
  506.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  507.                                 TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  508.                                 TMV6 = (.V_Data[8] Shl 24) Or (.V_Data[9] Shl 16) Or (.V_Data[10] Shl 8) Or .V_Data[11]
    
  509.                                 TMV7 = (.V_Data[12] Shl 24) Or (.V_Data[13] Shl 16) Or (.V_Data[14] Shl 8) Or .V_Data[15]
    
  510.                                 If (Len(.V_Data) - 16) >= TMV7 Then
    
  511.                                     TMS0 = Mid(.V_Data, 17, TMV7)
    
  512.                                     TSNEPlay_INT_Event_Message(TMV0, TMV1, TMS0, Cast(TSNEPlay_MessageType_Enum, TMV6))
    
  513.                                 End If
    
  514.                             End If
    
  515.                         End If
    
  516.                         
    
  517.                     Case TSNEPlay_INT_MSGT_Move
    
  518.                         If TSNEPlay_INT_Event_Move <> 0 Then
    
  519.                             If Len(.V_Data) >= 35 Then
    
  520.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  521.                                 TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  522.                                 TMV2 = (.V_Data[8] Shl 56) Or (.V_Data[9] Shl 48) Or (.V_Data[10] Shl 40) Or (.V_Data[11] Shl 32) Or (.V_Data[12] Shl 24) Or (.V_Data[13] Shl 16) Or (.V_Data[14] Shl 8) Or .V_Data[15]
    
  523.                                 TMV3 = (.V_Data[16] Shl 56) Or (.V_Data[17] Shl 48) Or (.V_Data[18] Shl 40) Or (.V_Data[19] Shl 32) Or (.V_Data[20] Shl 24) Or (.V_Data[21] Shl 16) Or (.V_Data[22] Shl 8) Or .V_Data[23]
    
  524.                                 TMV4 = (.V_Data[24] Shl 56) Or (.V_Data[25] Shl 48) Or (.V_Data[26] Shl 40) Or (.V_Data[27] Shl 32) Or (.V_Data[28] Shl 24) Or (.V_Data[29] Shl 16) Or (.V_Data[30] Shl 8) Or .V_Data[31]
    
  525.                                 TMV5 = (.V_Data[32] Shl 24) Or (.V_Data[33] Shl 16) Or (.V_Data[34] Shl 8) Or .V_Data[35]
    
  526.                                 TSNEPlay_INT_Event_Move(TMV0, TMV1, TMV2, TMV3, TMV4, TMV5)
    
  527.                             End If
    
  528.                         End If
    
  529.                         
    
  530.                     Case TSNEPlay_INT_MSGT_Dat
    
  531.                         If TSNEPlay_INT_Event_Data <> 0 Then
    
  532.                             If Len(.V_Data) >= 12 Then
    
  533.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  534.                                 TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  535.                                 TMV6 = (.V_Data[8] Shl 24) Or (.V_Data[9] Shl 16) Or (.V_Data[10] Shl 8) Or .V_Data[11]
    
  536.                                 If (Len(.V_Data) - 12) >= TMV6 Then
    
  537.                                     TMS0 = Mid(.V_Data, 13, TMV6)
    
  538.                                     TSNEPlay_INT_Event_Data(TMV0, TMV1, TMS0)
    
  539.                                 End If
    
  540.                             End If
    
  541.                         End If
    
  542.                         
    
  543.                     Case TSNEPlay_INT_MSGT_Con
    
  544.                         If TSNEPlay_INT_Event_Player_Connected <> 0 Then
    
  545.                             If Len(.V_Data) >= 8 Then
    
  546.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  547.                                 TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  548.                                 If (Len(.V_Data) - 8) >= TMV1 Then
    
  549.                                     TMS0 = Mid(.V_Data, 9, TMV1)
    
  550.                                     .V_Data = Mid(.V_Data, 9 + TMV1)
    
  551.                                     TMV1 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  552.                                     If (Len(.V_Data) - 4) >= TMV1 Then
    
  553.                                         TMS1 = Mid(.V_Data, 5, TMV1)
    
  554.                                         TSNEPlay_INT_Event_Player_Connected(TMV0, TMS0, TMS1)
    
  555.                                     End If
    
  556.                                 End If
    
  557.                             End If
    
  558.                         End If
    
  559.                         
    
  560.                     Case TSNEPlay_INT_MSGT_Dis
    
  561.                         If TSNEPlay_INT_Event_Player_Disconnected <> 0 Then
    
  562.                             If Len(.V_Data) >= 4 Then
    
  563.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  564.                                 TSNEPlay_INT_Event_Player_Disconnected(TMV0)
    
  565.                             End If
    
  566.                         End If
    
  567.                         
    
  568.                 End Select
    
  569.             Else
    
  570.                 Select Case .V_CMDType
    
  571.                     Case TSNEPlay_INT_MSGT_Unknown
    
  572.                     Case TSNEPlay_INT_MSGT_Password
    
  573.                         If .V_Data <> TSNEPlay_INT_ServerPassword Then
    
  574.                             XErrExit = 1
    
  575.                             TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Ready))
    
  576.                         Else: TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_GetInfo, Str(TCInfo.V_PlayerID)))
    
  577.                         End If
    
  578.                         
    
  579.                     Case TSNEPlay_INT_MSGT_GetInfo
    
  580.                         
    
  581.                     Case TSNEPlay_INT_MSGT_PutInfo
    
  582.                         If (TCInfo.V_State = TSNEPlay_State_Connected) Or (TCInfo.V_State = TSNEPlay_State_Login) Then
    
  583.                             If Len(.V_Data) >= 4 Then
    
  584.                                 TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  585.                                 TMS0 = Mid(.V_Data, 5, TMV0)
    
  586.                                 Mutexlock(TSNEPlay_INT_Mutex)
    
  587.                                 TPtr = TSNEPlay_INT_ClientGetTSNEID(V_TSNEID)
    
  588.                                 If TPtr > 0 Then
    
  589.                                     TPtr->V_Nickname = TMS0
    
  590.                                     TPtr->V_State = TSNEPlay_State_Ready
    
  591.                                 End If
    
  592.                                 Mutexunlock(TSNEPlay_INT_Mutex)
    
  593.                                 TSNE_Data_Send(V_TSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Ready))
    
  594.                                 TSNEPlay_INT_Event_Player_Connected(TCInfo.V_PlayerID, TCInfo.V_IPA, TMS0)
    
  595.                                 TMS1 += Chr((TCInfo.V_PlayerID Shr 24) And 255) & Chr((TCInfo.V_PlayerID Shr 16) And 255) & Chr((TCInfo.V_PlayerID Shr 8) And 255) & Chr(TCInfo.V_PlayerID And 255)
    
  596.                                 TMV0 = 0: TMS1 += Chr((TMV0 Shr 24) And 255) & Chr((TMV0 Shr 16) And 255) & Chr((TMV0 Shr 8) And 255) & Chr(TMV0 And 255)
    
  597.                                 TMS1 += ""
    
  598.                                 TMV0 = Len(TMS0): TMS1 += Chr((TMV0 Shr 24) And 255) & Chr((TMV0 Shr 16) And 255) & Chr((TMV0 Shr 8) And 255) & Chr(TMV0 And 255)
    
  599.                                 TMS1 += TMS0
    
  600.                                 TMS1 = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Con, TMS1)
    
  601.                                 RV = TSNEPlay_INT_SendData(0, TMS1, TLocalSend)
    
  602.                                 TSNEPlay_INT_SendPlayerTable(V_TSNEID)
    
  603.                             End If
    
  604.                         End If
    
  605.                         
    
  606.                     Case TSNEPlay_INT_MSGT_Ready
    
  607.                         
    
  608.                     Case TSNEPlay_INT_MSGT_StreamError
    
  609.                         XErrExit = 1
    
  610.                         
    
  611.                     Case TSNEPlay_INT_MSGT_Pong
    
  612.                         
    
  613.                     Case TSNEPlay_INT_MSGT_MSG
    
  614.                         If Len(.V_Data) >= 16 Then
    
  615.                             TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  616.                             RV = TSNEPlay_INT_SendData(TMV1, .V_RAW, TLocalSend)
    
  617.                             If TLocalSend = 1 Then
    
  618.                                 If TSNEPlay_INT_Event_Message <> 0 Then
    
  619.                                     TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  620.                                     TMV6 = (.V_Data[8] Shl 24) Or (.V_Data[9] Shl 16) Or (.V_Data[10] Shl 8) Or .V_Data[11]
    
  621.                                     TMV7 = (.V_Data[12] Shl 24) Or (.V_Data[13] Shl 16) Or (.V_Data[14] Shl 8) Or .V_Data[15]
    
  622.                                     If (Len(.V_Data) - 16) >= TMV7 Then
    
  623.                                         TMS0 = Mid(.V_Data, 17, TMV7)
    
  624.                                         TSNEPlay_INT_Event_Message(TMV0, TMV1, TMS0, Cast(TSNEPlay_MessageType_Enum, TMV6))
    
  625.                                     End If
    
  626.                                 End If
    
  627.                             End If
    
  628.                         End If
    
  629.                         
    
  630.                     Case TSNEPlay_INT_MSGT_Move
    
  631.                         If Len(.V_Data) >= 24 Then
    
  632.                             TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  633.                             RV = TSNEPlay_INT_SendData(TMV1, .V_RAW, TLocalSend)
    
  634.                             If TLocalSend = 1 Then
    
  635.                                 If TSNEPlay_INT_Event_Move <> 0 Then
    
  636.                                     TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  637.                                     TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  638.                                     TMV2 = (.V_Data[8] Shl 56) Or (.V_Data[9] Shl 48) Or (.V_Data[10] Shl 40) Or (.V_Data[11] Shl 32) Or (.V_Data[12] Shl 24) Or (.V_Data[13] Shl 16) Or (.V_Data[14] Shl 8) Or .V_Data[15]
    
  639.                                     TMV3 = (.V_Data[16] Shl 56) Or (.V_Data[17] Shl 48) Or (.V_Data[18] Shl 40) Or (.V_Data[19] Shl 32) Or (.V_Data[20] Shl 24) Or (.V_Data[21] Shl 16) Or (.V_Data[22] Shl 8) Or .V_Data[23]
    
  640.                                     TMV4 = (.V_Data[24] Shl 56) Or (.V_Data[25] Shl 48) Or (.V_Data[26] Shl 40) Or (.V_Data[27] Shl 32) Or (.V_Data[28] Shl 24) Or (.V_Data[29] Shl 16) Or (.V_Data[30] Shl 8) Or .V_Data[31]
    
  641.                                     TMV5 = (.V_Data[32] Shl 24) Or (.V_Data[33] Shl 16) Or (.V_Data[34] Shl 8) Or .V_Data[35]
    
  642.                                     TSNEPlay_INT_Event_Move(TMV0, TMV1, TMV2, TMV3, TMV4, TMV5)
    
  643.                                 End If
    
  644.                             End If
    
  645.                         End If
    
  646.                         
    
  647.                     Case TSNEPlay_INT_MSGT_Dat
    
  648.                         If Len(.V_Data) >= 12 Then
    
  649.                             TMV1 = (.V_Data[4] Shl 24) Or (.V_Data[5] Shl 16) Or (.V_Data[6] Shl 8) Or .V_Data[7]
    
  650.                             RV = TSNEPlay_INT_SendData(TMV1, .V_RAW, TLocalSend)
    
  651.                             If TLocalSend = 1 Then
    
  652.                                 If TSNEPlay_INT_Event_Data <> 0 Then
    
  653.                                     TMV0 = (.V_Data[0] Shl 24) Or (.V_Data[1] Shl 16) Or (.V_Data[2] Shl 8) Or .V_Data[3]
    
  654.                                     TMV6 = (.V_Data[8] Shl 24) Or (.V_Data[9] Shl 16) Or (.V_Data[10] Shl 8) Or .V_Data[11]
    
  655.                                     If (Len(.V_Data) - 12) >= TMV6 Then
    
  656.                                         TMS0 = Mid(.V_Data, 13, TMV6)
    
  657.                                         TSNEPlay_INT_Event_Data(TMV0, TMV1, TMS0)
    
  658.                                     End If
    
  659.                                 End If
    
  660.                             End If
    
  661.                         End If
    
  662.                         
    
  663.                 End Select
    
  664.             End If
    
  665.         End With
    
  666.     End If
    
  667.     Deallocate(TCMDQueF)
    
  668.     TCMDQueF = TCMDQueL
    
  669. Loop
    
  670. If XErrExit = 1 Then TSNE_Disconnect(V_TSNEID)
    
  671. End Sub
    
  672. 
    
  673. '--------------------------------------------------------------------------------------------------------------
    
  674. Sub TSNEPlay_INT_NewConnection(Byval V_TSNEID As Uinteger, Byval V_RequestID As Socket, Byval V_IPA As String)
    
  675. 'Print "NEW:"; V_TSNEID; " "; V_IPA
    
  676. Dim RV As Integer
    
  677. Dim TNewTSNEID As Uinteger
    
  678. Mutexlock(TSNEPlay_INT_Mutex)
    
  679. If TSNEPlay_INT_ClientC >= TSNEPlay_INT_Server_MaxPlayer Then
    
  680.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  681.     RV = TSNE_Create_Accept(V_RequestID, TNewTSNEID, , @TSNEPlay_INT_Disconnected, @TSNEPlay_INT_Connected, 0)
    
  682.     RV = TSNE_Data_Send(TNewTSNEID, TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Full))
    
  683.     RV = TSNE_Disconnect(TNewTSNEID)
    
  684.     Exit Sub
    
  685. End If
    
  686. RV = TSNE_Create_Accept(V_RequestID, TNewTSNEID, , @TSNEPlay_INT_Disconnected, @TSNEPlay_INT_Connected, @TSNEPlay_INT_NewData)
    
  687. Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientAdd()
    
  688. With *TPtr
    
  689.     .V_TSNEID       = TNewTSNEID
    
  690.     .V_IPA          = V_IPA
    
  691.     .V_State        = TSNEPlay_State_Connecting
    
  692. End With
    
  693. Mutexunlock(TSNEPlay_INT_Mutex)
    
  694. End Sub
    
  695. 
    
  696. 
    
  697. 
    
  698. '##############################################################################################################
    
  699. Function TSNEPlay_CreateServer(V_MaxPlayer As Ushort, V_Port As Ushort, V_Nickname As String, V_Password As String = "", Byval V_EventPtr_ConnectionState As Any Ptr = 0, Byval V_EventPtr_Player_Connected As Any Ptr, Byval V_EventPtr_Player_Disconnected As Any Ptr, Byval V_EventPtr_Message As Any Ptr, Byval V_EventPtr_Move As Any Ptr, Byval V_EventPtr_Data As Any Ptr, V_NoSelfPlayer As Ubyte = 1) As TSNEPlay_GURUCode
    
  700. If TSNEPlay_INT_State <> TSNEPlay_State_Unknown Then Return TSNEPlay_NotReadyForNewConnection
    
  701. TSNEPlay_INT_Client_PlayerID = 0
    
  702. TSNEPlay_INT_Server_MaxPlayer = V_MaxPlayer
    
  703. TSNEPlay_INT_ServerPassword = V_Password
    
  704. TSNEPlay_INT_Nickname = V_Nickname
    
  705. TSNEPlay_INT_ClientMode = 0
    
  706. TSNEPlay_INT_Event_ConnectionState      = V_EventPtr_ConnectionState
    
  707. TSNEPlay_INT_Event_Player_Connected     = V_EventPtr_Player_Connected
    
  708. TSNEPlay_INT_Event_Player_Disconnected  = V_EventPtr_Player_Disconnected
    
  709. TSNEPlay_INT_Event_Message              = V_EventPtr_Message
    
  710. TSNEPlay_INT_Event_Move                 = V_EventPtr_Move
    
  711. TSNEPlay_INT_Event_Data                 = V_EventPtr_Data
    
  712. TSNEPlay_INT_State = TSNEPlay_State_Connecting
    
  713. If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  714. Dim RV As Integer = TSNE_Create_Server(TSNEPlay_INT_Server_TSNEID, V_Port, 100, @TSNEPlay_INT_NewConnection)
    
  715. If RV <> TSNE_Const_NoError Then TSNEPlay_INT_State = TSNEPlay_State_Unknown: Return RV
    
  716. If V_NoSelfPlayer = 0 Then
    
  717.     Dim TPtr As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientAdd()
    
  718.     With *TPtr
    
  719.         TSNEPlay_INT_Server_PlayerID = .V_PlayerID
    
  720.         .V_Nickname     = V_Nickname
    
  721.         .V_TSNEID       = 0
    
  722.         .V_IPA          = "127.0.0.1"
    
  723.         .V_State        = TSNEPlay_State_Ready
    
  724.     End With
    
  725. End If
    
  726. TSNEPlay_INT_State = TSNEPlay_State_Ready
    
  727. If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  728. Return TSNEPlay_NoError
    
  729. End Function
    
  730. 
    
  731. '--------------------------------------------------------------------------------------------------------------
    
  732. Function TSNEPlay_ConnectToServer(V_Host As String, V_Port As Ushort, V_Nickname As String, V_Password As String = "", Byval V_EventPtr_ConnectionState As Any Ptr = 0, Byval V_EventPtr_Player_Connected As Any Ptr, Byval V_EventPtr_Player_Disconnected As Any Ptr, Byval V_EventPtr_Message As Any Ptr, Byval V_EventPtr_Move As Any Ptr, Byval V_EventPtr_Data As Any Ptr) As TSNEPlay_GURUCode
    
  733. If TSNEPlay_INT_State <> TSNEPlay_State_Unknown Then Return TSNEPlay_NotReadyForNewConnection
    
  734. TSNEPlay_INT_Client_PlayerID = 0
    
  735. TSNEPlay_INT_ServerPassword = V_Password
    
  736. TSNEPlay_INT_Nickname = V_Nickname
    
  737. TSNEPlay_INT_ClientMode = 1
    
  738. TSNEPlay_INT_Event_ConnectionState      = V_EventPtr_ConnectionState
    
  739. TSNEPlay_INT_Event_Player_Connected     = V_EventPtr_Player_Connected
    
  740. TSNEPlay_INT_Event_Player_Disconnected  = V_EventPtr_Player_Disconnected
    
  741. TSNEPlay_INT_Event_Message              = V_EventPtr_Message
    
  742. TSNEPlay_INT_Event_Move                 = V_EventPtr_Move
    
  743. TSNEPlay_INT_Event_Data                 = V_EventPtr_Data
    
  744. TSNEPlay_INT_State = TSNEPlay_State_Connecting
    
  745. If TSNEPlay_INT_Event_ConnectionState <> 0 Then TSNEPlay_INT_Event_ConnectionState(TSNEPlay_INT_Client_PlayerID, TSNEPlay_INT_State)
    
  746. Dim RV As Integer = TSNE_Create_Client(TSNEPlay_INT_Client_TSNEID, V_Host, V_Port, @TSNEPlay_INT_Disconnected, @TSNEPlay_INT_Connected, @TSNEPlay_INT_NewData, 60)
    
  747. If RV <> TSNE_Const_NoError Then TSNEPlay_INT_State = TSNEPlay_State_Unknown: Return RV
    
  748. Return TSNEPlay_NoError
    
  749. End Function
    
  750. 
    
  751. '--------------------------------------------------------------------------------------------------------------
    
  752. Function TSNEPlay_CloseAll() As TSNEPlay_GURUCode
    
  753. If TSNEPlay_INT_Server_TSNEID <> 0 Then
    
  754.     TSNE_Disconnect(TSNEPlay_INT_Server_TSNEID)
    
  755.     TSNE_WaitClose(TSNEPlay_INT_Server_TSNEID)
    
  756.     TSNEPlay_INT_Server_TSNEID = 0
    
  757.     Mutexlock(TSNEPlay_INT_Mutex)
    
  758.     Dim TPtr1 As TSNEPlay_INT_Client_Type Ptr = TSNEPlay_INT_ClientF
    
  759.     Dim TPtr2 As TSNEPlay_INT_Client_Type Ptr
    
  760.     Dim TSID As Uinteger
    
  761.     Do Until TPtr1 = 0
    
  762.         TPtr2 = TPtr1->V_Next
    
  763.         TSID = TPtr1->V_TSNEID
    
  764.         If TSID > 0 Then TSNE_Disconnect(TSID)
    
  765.         TPtr1 = TPtr2
    
  766.     Loop
    
  767.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  768.     Mutexlock(TSNEPlay_INT_Mutex)
    
  769.     TPtr1 = TSNEPlay_INT_ClientF
    
  770.     Do Until TPtr1 = 0
    
  771.         TPtr2 = TPtr1->V_Next
    
  772.         TSID = TPtr1->V_TSNEID
    
  773.         If TSID > 0 Then
    
  774.             Mutexunlock(TSNEPlay_INT_Mutex)
    
  775.             TSNE_WaitClose(TSID)
    
  776.             Mutexlock(TSNEPlay_INT_Mutex)
    
  777.         End If
    
  778.         TPtr1 = TPtr2
    
  779.     Loop
    
  780.     TSNEPlay_INT_ClientF = 0
    
  781.     TSNEPlay_INT_ClientL = 0
    
  782.     Mutexunlock(TSNEPlay_INT_Mutex)
    
  783. End If
    
  784. If TSNEPlay_INT_Client_TSNEID <> 0 Then
    
  785.     TSNE_Disconnect(TSNEPlay_INT_Client_TSNEID)
    
  786.     TSNE_WaitClose(TSNEPlay_INT_Client_TSNEID)
    
  787.     TSNEPlay_INT_Client_TSNEID = 0
    
  788. End If
    
  789. TSNEPlay_INT_State = TSNEPlay_State_Unknown
    
  790. TSNEPlay_INT_Server_MaxPlayer = 0
    
  791. TSNEPlay_INT_ServerPassword = ""
    
  792. TSNEPlay_INT_Nickname = ""
    
  793. TSNEPlay_INT_ClientMode = 0
    
  794. TSNEPlay_INT_Event_ConnectionState      = 0
    
  795. TSNEPlay_INT_Event_Player_Connected     = 0
    
  796. TSNEPlay_INT_Event_Player_Disconnected  = 0
    
  797. TSNEPlay_INT_Event_Message              = 0
    
  798. TSNEPlay_INT_Event_Move                 = 0
    
  799. TSNEPlay_INT_Event_Data                 = 0
    
  800. Return TSNEPlay_NoError
    
  801. End Function
    
  802. 
    
  803. 
    
  804. 
    
  805. '##############################################################################################################
    
  806. Function TSNEPlay_Connection_GetState() As TSNEPlay_State_Enum
    
  807. Return TSNEPlay_INT_State
    
  808. End Function
    
  809. 
    
  810. 
    
  811. 
    
  812. '##############################################################################################################
    
  813. Function TSNEPlay_SendMSG(V_ToPlayerID As Uinteger, V_Message As String, V_MessageType As TSNEPlay_MessageType_Enum = TSNEPlay_MSGType_Regular) As TSNEPlay_GURUCode
    
  814. '<FromPlayerID><ToPlayerID><MSGType><MSG>
    
  815. If Len(V_Message) > 4096 Then Return TSNEPlay_MessageToLong
    
  816. If TSNEPlay_INT_State <> TSNEPlay_State_Ready Then Return TSNEPlay_NotReadyForNewConnection
    
  817. Dim T As String
    
  818. Dim FPID As Uinteger
    
  819. If TSNEPlay_INT_ClientMode = 1 Then
    
  820.     FPID = TSNEPlay_INT_Client_PlayerID
    
  821. Else: FPID = TSNEPlay_INT_Server_PlayerID
    
  822. End If
    
  823. T += Chr((FPID Shr 24) And 255) & Chr((FPID Shr 16) And 255) & Chr((FPID Shr 8) And 255) & Chr(FPID And 255)
    
  824. T += Chr((V_ToPlayerID Shr 24) And 255) & Chr((V_ToPlayerID Shr 16) And 255) & Chr((V_ToPlayerID Shr 8) And 255) & Chr(V_ToPlayerID And 255)
    
  825. T += Chr((V_MessageType Shr 24) And 255) & Chr((V_MessageType Shr 16) And 255) & Chr((V_MessageType Shr 8) And 255) & Chr(V_MessageType And 255)
    
  826. Dim MX As Uinteger = Len(V_Message)
    
  827. T += Chr((MX Shr 24) And 255) & Chr((MX Shr 16) And 255) & Chr((MX Shr 8) And 255) & Chr(MX And 255)
    
  828. T += V_Message
    
  829. T = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_MSG, T)
    
  830. Dim TLocalSend As Ubyte
    
  831. Dim RV As TSNEPlay_GURUCode = TSNEPlay_INT_SendData(V_ToPlayerID, T, TLocalSend)
    
  832. If TLocalSend = 1 Then If TSNEPlay_INT_Event_Message <> 0 Then TSNEPlay_INT_Event_Message(FPID, V_ToPlayerID, V_Message, V_MessageType)
    
  833. Return RV
    
  834. End Function
    
  835. 
    
  836. '--------------------------------------------------------------------------------------------------------------
    
  837. Function TSNEPlay_SendMove(V_ToPlayerID As Uinteger, V_NewPositonX As Double = 0, V_NewPositonY As Double = 0, V_NewPositonZ As Double = 0, Byval V_SubData As Uinteger = 0) As TSNEPlay_GURUCode
    
  838. '<FromPlayerID><ToPlayerID><PosX><PosY><PosZ><SubData>
    
  839. If TSNEPlay_INT_State <> TSNEPlay_State_Ready Then Return TSNEPlay_NotReadyForNewConnection
    
  840. Dim T As String
    
  841. Dim FPID As Uinteger
    
  842. If TSNEPlay_INT_ClientMode = 1 Then
    
  843.     FPID = TSNEPlay_INT_Client_PlayerID
    
  844. Else: FPID = TSNEPlay_INT_Server_PlayerID
    
  845. End If
    
  846. T += Chr((FPID Shr 24) And 255) & Chr((FPID Shr 16) And 255) & Chr((FPID Shr 8) And 255) & Chr(FPID And 255)
    
  847. T += Chr((V_ToPlayerID Shr 24) And 255) & Chr((V_ToPlayerID Shr 16) And 255) & Chr((V_ToPlayerID Shr 8) And 255) & Chr(V_ToPlayerID And 255)
    
  848. 
    
  849. 
    
  850. 
    
  851. T += Chr((V_NewPositonX Shr 56) And 255) & Chr((V_NewPositonX Shr 48) And 255) & Chr((V_NewPositonX Shr 40) And 255) & Chr((V_NewPositonX Shr 32) And 255) & Chr((V_NewPositonX Shr 24) And 255) & Chr((V_NewPositonX Shr 16) And 255) & Chr((V_NewPositonX Shr 8) And 255) & Chr(V_NewPositonX And 255)
    
  852. T += Chr((V_NewPositonY Shr 56) And 255) & Chr((V_NewPositonY Shr 48) And 255) & Chr((V_NewPositonY Shr 40) And 255) & Chr((V_NewPositonY Shr 32) And 255) & Chr((V_NewPositonY Shr 24) And 255) & Chr((V_NewPositonY Shr 16) And 255) & Chr((V_NewPositonY Shr 8) And 255) & Chr(V_NewPositonY And 255)
    
  853. T += Chr((V_NewPositonZ Shr 56) And 255) & Chr((V_NewPositonZ Shr 48) And 255) & Chr((V_NewPositonZ Shr 40) And 255) & Chr((V_NewPositonZ Shr 32) And 255) & Chr((V_NewPositonZ Shr 24) And 255) & Chr((V_NewPositonZ Shr 16) And 255) & Chr((V_NewPositonZ Shr 8) And 255) & Chr(V_NewPositonZ And 255)
    
  854. T += Chr((V_SubData Shr 24) And 255) & Chr((V_SubData Shr 16) And 255) & Chr((V_SubData Shr 8) And 255) & Chr(V_SubData And 255)
    
  855. T = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Move, T)
    
  856. Dim TLocalSend As Ubyte
    
  857. Dim RV As TSNEPlay_GURUCode = TSNEPlay_INT_SendData(V_ToPlayerID, T, TLocalSend)
    
  858. If TLocalSend = 1 Then If TSNEPlay_INT_Event_Move <> 0 Then TSNEPlay_INT_Event_Move(FPID, V_ToPlayerID, V_NewPositonX, V_NewPositonY, V_NewPositonZ, V_SubData)
    
  859. Return RV
    
  860. End Function
    
  861. 
    
  862. '--------------------------------------------------------------------------------------------------------------
    
  863. Function TSNEPlay_SendData(V_ToPlayerID As Uinteger, Byref V_Data As String) As TSNEPlay_GURUCode
    
  864. '<FromPlayerID><ToPlayerID><Data>
    
  865. If Len(V_Data) > (TSNE_INT_BufferSize - 24) Then Return TSNEPlay_MessageToLong
    
  866. If TSNEPlay_INT_State <> TSNEPlay_State_Ready Then Return TSNEPlay_NotReadyForNewConnection
    
  867. Dim T As String
    
  868. Dim FPID As Uinteger
    
  869. If TSNEPlay_INT_ClientMode = 1 Then
    
  870.     FPID = TSNEPlay_INT_Client_PlayerID
    
  871. Else: FPID = TSNEPlay_INT_Server_PlayerID
    
  872. End If
    
  873. T += Chr((FPID Shr 24) And 255) & Chr((FPID Shr 16) And 255) & Chr((FPID Shr 8) And 255) & Chr(FPID And 255)
    
  874. T += Chr((V_ToPlayerID Shr 24) And 255) & Chr((V_ToPlayerID Shr 16) And 255) & Chr((V_ToPlayerID Shr 8) And 255) & Chr(V_ToPlayerID And 255)
    
  875. Dim MX As Uinteger = Len(V_Data)
    
  876. T += Chr((MX Shr 24) And 255) & Chr((MX Shr 16) And 255) & Chr((MX Shr 8) And 255) & Chr(MX And 255)
    
  877. T += V_Data
    
  878. T = TSNEPlay_INT_CreateStreamCommand(TSNEPlay_INT_MSGT_Dat, T)
    
  879. Dim TLocalSend As Ubyte
    
  880. Dim RV As TSNEPlay_GURUCode = TSNEPlay_INT_SendData(V_ToPlayerID, T, TLocalSend)
    
  881. If TLocalSend = 1 Then If TSNEPlay_INT_Event_Data <> 0 Then TSNEPlay_INT_Event_Data(FPID, V_ToPlayerID, V_Data)
    
  882. Return RV
    
  883. End Function
    
  884. 
    
  885. 
    
  886. 
    
  887. '##############################################################################################################
    
  888. '...<
    
  889. #ENDIF
    
  890. 
    
  891.