@@ -99,21 +99,22 @@ public void listenerThread()
99
99
}
100
100
101
101
//触发事件只发id
102
+ //在jsmod2的监听器执行完前不能停止,get为true,在read处阻塞
102
103
public void sendEventObject ( Event e , int id , IdMapping mapping )
103
104
{
104
- sendObject ( "{}" , id , mapping ) ;
105
+ sendObject ( "{}" , id , mapping , true ) ;
105
106
}
106
107
107
- public void sendObject ( string json1 , int id , IdMapping mapping )
108
+ public void sendObject ( string json1 , int id , IdMapping mapping , bool get )
108
109
{
109
- sendObject ( new TcpClient ( ) , json1 , id , mapping ) ;
110
+ sendObject ( new TcpClient ( ) , json1 , id , mapping , get ) ;
110
111
}
111
112
112
- public void sendObject ( TcpClient tcp , string json1 , int id , IdMapping mapping )
113
+ public void sendObject ( TcpClient tcp , string json1 , int id , IdMapping mapping , bool get )
113
114
{
114
115
//如何定位物品,并设置,通过itemMapping找到id归属对象(player这个字段就是id)
115
116
//然后通过id定位到物品,并设置
116
- send ( getProtocol ( json1 , id , mapping ) , tcp ) ;
117
+ send ( getProtocol ( json1 , id , mapping ) , tcp , get ) ;
117
118
}
118
119
119
120
//发送协议集合,用于传输物品数组,有多个不同的id
@@ -135,7 +136,8 @@ public void sendObjects(JsonSetting[] settings)
135
136
{
136
137
sendObjects ( new TcpClient ( ) , settings ) ;
137
138
}
138
- private void send ( string jsons , TcpClient tcp )
139
+
140
+ private void send ( string jsons , TcpClient tcp , bool get )
139
141
{
140
142
try
141
143
{
@@ -144,16 +146,28 @@ private void send(string jsons,TcpClient tcp)
144
146
byte [ ] bytes = utf8WithoutBom . GetBytes ( Convert . ToBase64String ( utf8WithoutBom . GetBytes ( jsons ) ) ) ;
145
147
if ( ! tcp . Connected )
146
148
{
147
- tcp . Connect ( new IPEndPoint ( IPAddress . Parse ( reader . get ( "jsmod2.ip" ) ) , port ) ) ;
149
+ tcp . Connect ( new IPEndPoint ( IPAddress . Parse ( reader . get ( "jsmod2.ip" ) ) , port ) ) ;
148
150
}
149
-
151
+
150
152
tcp . GetStream ( ) . Write ( bytes , 0 , bytes . Length ) ;
153
+ if ( get )
154
+ {
155
+ tcp . GetStream ( ) . ReadByte ( ) ; //停止
156
+ }
151
157
}
152
158
catch ( Exception e )
153
159
{
154
160
Error ( e . Message ) ;
155
161
}
156
-
162
+ finally
163
+ {
164
+ tcp . Close ( ) ;
165
+ }
166
+ }
167
+ private void send ( string jsons , TcpClient tcp )
168
+ {
169
+
170
+ send ( jsons , tcp , false ) ;
157
171
158
172
}
159
173
0 commit comments