File tree Expand file tree Collapse file tree 5 files changed +30
-31
lines changed
server/src/main/java/info/xiaomo/server Expand file tree Collapse file tree 5 files changed +30
-31
lines changed Original file line number Diff line number Diff line change 44import info .xiaomo .gameCore .protocol .client .ClientBuilder ;
55import info .xiaomo .server .back .BackMessagePool ;
66import info .xiaomo .server .back .BackMessageRouter ;
7+ import info .xiaomo .server .protocol .message .gm .ReqCloseServerMessage ;
78import info .xiaomo .server .server .ServerOption ;
89import org .slf4j .Logger ;
910import org .slf4j .LoggerFactory ;
@@ -14,7 +15,7 @@ public class StopServerClient {
1415 public static void main (String [] args ) throws Exception {
1516
1617 try {
17- String optionPath = args [ 0 ] ;
18+ String optionPath = "config.properties" ;
1819 BackMessagePool pool = new BackMessagePool ();
1920 ServerOption option = new ServerOption (optionPath );
2021 ClientBuilder builder = new ClientBuilder ();
@@ -25,9 +26,9 @@ public static void main(String[] args) throws Exception {
2526
2627 Client client = builder .createClient ();
2728 client .connect (false );
28-
29+ ReqCloseServerMessage msg = new ReqCloseServerMessage ();
2930 Thread .sleep (1000 );
30- // client.sendMsg(msg);
31+ client .sendMsg (msg );
3132 int count = 10 ;
3233 while (count > 0 ) {
3334 Thread .sleep (10 * 1000 );
Original file line number Diff line number Diff line change 33
44import info .xiaomo .gameCore .protocol .Message ;
55import info .xiaomo .gameCore .protocol .MessagePool ;
6+ import info .xiaomo .server .protocol .message .gm .ReqCloseServerMessage ;
67
78import java .util .HashMap ;
89import java .util .Map ;
@@ -27,7 +28,7 @@ public class BackMessagePool implements MessagePool {
2728 private final Map <Integer , Class <? extends Message >> messages = new HashMap <>();
2829
2930 public BackMessagePool () {
30-
31+ register ( new ReqCloseServerMessage (). getId (), ReqCloseServerMessage . class );
3132 }
3233
3334 @ Override
Original file line number Diff line number Diff line change 11package info .xiaomo .server .protocol .message .gm ;
22
3+ import info .xiaomo .server .back .BackManager ;
34import info .xiaomo .server .server .AbstractMessage ;
4- import info .xiaomo .server .protocol .proto .GMProto .CloseServerRequest ;
5- import com .google .protobuf .InvalidProtocolBufferException ;
65
76public class ReqCloseServerMessage extends AbstractMessage {
87
9- private CloseServerRequest req ;
8+ public ReqCloseServerMessage () {
9+ this .queueId = 2 ;
10+ }
11+
1012
1113 @ Override
1214 public void doAction () {
13-
15+ BackManager . getInstance (). closeServer ();
1416 }
1517
16- @ Override
17- public void decode (byte [] bytes ) throws InvalidProtocolBufferException {
18- this .req = CloseServerRequest .parseFrom (bytes );
19- }
20-
2118 @ Override
2219 public int getId () {
2320 return 201 ;
2421 }
2522
26-
27-
2823}
2924
Original file line number Diff line number Diff line change 11package info .xiaomo .server .protocol .message .gm ;
22
33import com .google .protobuf .InvalidProtocolBufferException ;
4- import info .xiaomo .server .protocol .proto .GMProto .CloseServerResponse ;
54import info .xiaomo .server .server .AbstractMessage ;
5+ import info .xiaomo .server .protocol .proto .GMProto .CloseServerResponse ;
66
77/**
88 * 关服返回
99 */
1010public class ResCloseServerMessage extends AbstractMessage {
1111
12- private CloseServerResponse closeServerResponse ;
12+ private CloseServerResponse res ;
1313
14- @ Override
15- public void decode (byte [] bytes ) throws InvalidProtocolBufferException {
16- this .closeServerResponse = CloseServerResponse .parseFrom (bytes );
17- }
14+ @ Override
15+ public void decode (byte [] bytes ) throws InvalidProtocolBufferException {
16+ this .res = CloseServerResponse .parseFrom (bytes );
17+ }
1818
19+ @ Override
20+ public int getId () {
21+ return 2202 ;
22+ }
1923
20- @ Override
21- public int getId () {
22- return 2202 ;
23- }
24-
25- public CloseServerResponse getCloseServerResponse () {
26- return closeServerResponse ;
27- }
2824
29- public void setCloseServerResponse (CloseServerResponse closeServerResponse ) {
30- this .closeServerResponse = closeServerResponse ;
25+ @ Override
26+ public byte [] getContent () {
27+ return res .toByteArray ();
3128 }
3229
30+ public void setCloseServerResponse (CloseServerResponse res ) {
31+ this .res = res ;
32+ }
3333}
3434
Original file line number Diff line number Diff line change 22
33import info .xiaomo .gameCore .protocol .Message ;
44import info .xiaomo .gameCore .protocol .MessagePool ;
5+ import info .xiaomo .server .protocol .message .gm .ReqCloseServerMessage ;
56import info .xiaomo .server .protocol .message .user .ReqLoginMessage ;
67
78import java .util .HashMap ;
@@ -14,6 +15,7 @@ public class GameMessagePool implements MessagePool {
1415
1516 public GameMessagePool () {
1617 register (new ReqLoginMessage ().getId (), ReqLoginMessage .class );
18+ register (new ReqCloseServerMessage ().getId (), ReqCloseServerMessage .class );
1719 }
1820
1921 @ Override
You can’t perform that action at this time.
0 commit comments