1 #Region "Microsoft.VisualBasic::758cc9918a9da55982bf9c28321da545, Microsoft.VisualBasic.Core\Net\Tcp\Persistent\Protocols\Protocol.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Module ServicesProtocol
35     
36     
37     '         Enum Protocols
38     
39     '             Broadcast, ConfigConnection, GetMyIPAddress, IsUserOnline, SendMessage
40     '             ServerHash
41     
42     
43     
44     '  
45     
46     '     Properties: EntryPoint
47     
48     '     Function: BroadcastMessage, GetLogOnUSER, GetSendMessage, GetServicesConnection, IsUserOnlineRequest
49     '               LogOnRequest, SendChannelHashCode, SendMessageRequest
50     
51     
52     ' /********************************************************************************/
53
54 #End Region
55
56 Imports System.Runtime.CompilerServices
57 Imports Microsoft.VisualBasic.Net.Protocols
58 Imports Microsoft.VisualBasic.Net.Protocols.Reflection
59
60 Namespace Net.Tcp.Persistent.Application.Protocols
61
62     Public Module ServicesProtocol
63
64         Public Enum Protocols As Long
65             Logon = 59867
66             ServerHash
67             SendMessage
68             ConfigConnection
69             IsUserOnline
70             GetMyIPAddress
71             Broadcast
72         End Enum
73
74         Public ReadOnly Property EntryPoint As Long = New Protocol(GetType(Protocols)).EntryPoint
75
76         <MethodImpl(MethodImplOptions.AggressiveInlining)>
77         Public Function SendChannelHashCode(hash As IntegerAs RequestStream
78             Return New RequestStream(EntryPoint, Protocols.ServerHash, CStr(hash))
79         End Function
80
81         Public Const WorkSocketPortal As Integer = 66982
82
83         Public Function LogOnRequest(USER_ID As Long, Socket As StringAs RequestStream
84             Dim post As String = New LogonPOST With {
85                 .Socket = Socket,
86                 .USER_ID = USER_ID
87             }.GetXml
88             Return New RequestStream(EntryPoint, Protocols.Logon, post)
89         End Function
90
91         Public Function GetLogOnUSER(request As StringByRef USER_ID As LongByRef Socket As StringAs Boolean
92             Dim post As LogonPOST = request.LoadFromXml(Of LogonPOST)(False)
93
94             If post Is Nothing Then
95                 Return False
96             Else
97                 USER_ID = post.USER_ID
98                 Socket = post.Socket
99
100                 Return USER_ID <> 0 AndAlso Not String.IsNullOrEmpty(Socket)
101             End If
102         End Function
103
104         Public Function SendMessageRequest([FROM] As Long, USER_ID As LongMessage As RequestStream) As RequestStream
105             Dim post As New SendMessagePost With {
106                 .FROM = FROM,
107                 .Message = Message,
108                 .USER_ID = USER_ID
109             }
110             Return New RequestStream(EntryPoint, Protocols.SendMessage, post.Serialize)
111         End Function
112
113         Public Function GetSendMessage(request As RequestStream, ByRef [FROM] As LongByRef USER_ID As LongAs Boolean
114             Dim post As SendMessagePost = New SendMessagePost(request.ChunkBuffer)
115
116             [FROM] = post.FROM
117             USER_ID = post.USER_ID
118
119             Return True
120         End Function
121
122         Public Function GetServicesConnection() As RequestStream
123             Return New RequestStream(EntryPoint, Protocols.ConfigConnection, "GET")
124         End Function
125
126         Public Function IsUserOnlineRequest(USER_ID As LongAs RequestStream
127             Return New RequestStream(EntryPoint, Protocols.IsUserOnline, CStr(USER_ID))
128         End Function
129
130         Public Function BroadcastMessage(USER_ID As LongMessage As RequestStream) As RequestStream
131             Dim post As New BroadcastPOST With {
132                 .Message = Message,
133                 .USER_ID = USER_ID
134             }
135             Return New RequestStream(EntryPoint, Protocols.Broadcast, post.Serialize)
136         End Function
137     End Module
138 End Namespace