{"id":318480,"date":"2021-02-23T21:00:41","date_gmt":"2021-02-23T21:00:41","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318480"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318480","title":{"rendered":"\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Minecraft Query \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0432 .Net Core"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92b\/1e4\/911\/92b1e491144018ce7f2144470975ea70.png\" width=\"1475\" height=\"622\"><figcaption><\/figcaption><\/figure>\n<p><strong>Minecraft Server Query<\/strong> \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0443\u0442\u0451\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0430\u0440\u044b-\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0435\u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u044b\u0445 UDP-\u043f\u0430\u043a\u0435\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430 <a href=\"https:\/\/wiki.vg\/Query\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u043a\u0438<\/a> \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0440\u0430\u0437\u0438\u043b\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0443\u0446\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f .Net \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041f\u043e\u0438\u0441\u043a\u0430\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043b\u0438\u0431\u043e \u0438\u043c\u0435\u043b\u0438 \u0443\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u0445\u043e\u0442\u044f, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043a\u0443\u0434\u0430 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0440\u0435\u0437\u0430\u0442\u044c-\u0442\u043e.<\/p>\n<p>\u0422\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<h2>\u0421\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0442\u043e \u0442\u044b&#8230;<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0430\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Minecraft Query. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/wiki.vg\/Query\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u043a\u0438<\/a>, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432 \u0440\u0430\u0441\u043f\u043e\u0440\u044f\u0436\u0435\u043d\u0438\u0438 3 \u0432\u0438\u0434\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, 3 \u0432\u0438\u0434\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>Handshake<\/p>\n<\/li>\n<li>\n<p>BasicStatus<\/p>\n<\/li>\n<li>\n<p>FullStatus<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0430\u043a\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f <strong>ChallengeToken<\/strong>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0432\u0443\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043d \u043a IP-\u0430\u0434\u0440\u0435\u0441\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u043d\u0430 <strong>30 \u0441\u0435\u043a\u0443\u043d\u0434<\/strong>. \u0421\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0434\u0432\u0443\u0445 \u044f\u0441\u043d\u0430 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430 \u043b\u0438\u0448\u044c \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u043d\u0446\u0430\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u043c\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0442\u0432\u0435\u0442 BasicStatus<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ff\/af8\/2f5\/6ffaf82f5fd8ecdb009b454a7b647a4a.png\" alt=\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 BasicStatus\" title=\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 BasicStatus\" width=\"443\" height=\"272\"><figcaption>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 BasicStatus<\/figcaption><\/figure>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u2013 FullStatus<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f39\/0eb\/281\/f390eb2816fe872914a4f4136ef1cb78.png\" alt=\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 FullStatus\" title=\"\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 FullStatus\" width=\"813\" height=\"236\"><figcaption>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 FullStatus<\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u043e\u043c\u0438\u043c\u043e \u0442\u0435\u0445, \u0447\u0442\u043e \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 short, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 <em>big-endian<\/em>. \u0410 \u0434\u043b\u044f \u043f\u043e\u043b\u044f <strong>SessionId<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <em>SessionId &amp; 0x0F0F0F0F == SessionId<\/em>.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7fb\/b26\/12f\/7fbb2612faac762ef9e1a8b2c1f51301.png\" alt=\"\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435\" title=\"\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435\" width=\"389\" height=\"138\"><figcaption>\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435<\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u0432\u0438\u043a\u0438.<\/p>\n<h2>\u0418 \u044f \u0441\u043a\u0430\u0436\u0443 \u0442\u0435\u0431\u0435, \u043a\u0430\u043a \u0442\u0435\u0431\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435. \u0413\u043e\u0442\u043e\u0432\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c API \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 3 \u0432\u0438\u0434\u043e\u0432 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0440\u0430\u0441\u043f\u0430\u0440\u0448\u0435\u043d\u043e\u043c \u0432\u0438\u0434\u0435. <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u044f \u0445\u043e\u0447\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u044b \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0436\u0438\u0437\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f <strong>ChallengeToken<\/strong>. \u0415\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0442\u043e \u044f \u043d\u0435 \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u0434\u0432\u0430: \u0445\u044d\u043d\u0434\u0448\u0435\u0439\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 \u044f \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0437 \u0432 \u0447\u0430\u0441, \u0437\u0430\u0447\u0435\u043c \u043c\u043d\u0435 \u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a\u0430\u0436\u0434\u044b\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434? \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 &#171;\u0440\u0443\u0447\u043d\u043e\u043c&#187; \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432\u0448\u0438\u0441\u044c, \u043c\u043e\u0436\u0435\u043c \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u042f \u0432\u0438\u0436\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code class=\"cs\">public static async Task&lt;ServerState&gt; DoSomething(IPAddress host, int port) { \tvar mcQuery = new McQuery(host, port);   mcQuery.InitSocket();   await mcQuery.GetHandshake();   return await mcQuery.GetFullStatus(); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0432\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e (\u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438).<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u043a\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <strong>Request<\/strong>.<\/p>\n<pre><code class=\"cs\">public class Request { \t\t\/\/ \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430     private static readonly byte[] Magic = { 0xfe, 0xfd };     private static readonly byte[] Challenge = { 0x09 };     private static readonly byte[] Status = { 0x00 };        public byte[] Data { get; private set; }          private Request(){}      public byte RequestType =&gt; Data[2];      public static Request GetHandshakeRequest(SessionId sessionId)     {         var request = new Request();                \t\/\/ \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442         var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Challenge);         data.AddRange(sessionId.GetBytes());                  request.Data = data.ToArray();         return request;     }      public static Request GetBasicStatusRequest(SessionId sessionId, byte[] challengeToken)     {         if (challengeToken == null)         {             throw new ChallengeTokenIsNullException();         }                      var request = new Request();                  var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Status);         data.AddRange(sessionId.GetBytes());         data.AddRange(challengeToken);                  request.Data = data.ToArray();         return request;     }          public static Request GetFullStatusRequest(SessionId sessionId, byte[] challengeToken)     {         if (challengeToken == null)         {             throw new ChallengeTokenIsNullException();         }                  var request = new Request();                  var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Status);         data.AddRange(sessionId.GetBytes());         data.AddRange(challengeToken);         data.AddRange(new byte[] {0x00, 0x00, 0x00, 0x00}); \/\/ Padding                  request.Data = data.ToArray();         return request;     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e. \u0425\u0440\u0430\u043d\u0438\u043c \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u0432 \u0442\u0440\u0451\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445. \u041c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <strong>SessionId<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435, \u0442\u0430\u043a \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"cs\">public class SessionId {     private readonly byte[] _sessionId;      public SessionId (byte[] sessionId)     {         _sessionId = sessionId;     }  \t\t\/\/ \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 SessionId     public static SessionId GenerateRandomId()     {         var sessionId = new byte[4];         new Random().NextBytes(sessionId);         sessionId = sessionId.Select(@byte =&gt; (byte)(@byte &amp; 0x0F)).ToArray();         return new SessionId(sessionId);     }      public string GetString()     {         return BitConverter.ToString(_sessionId);     }      public byte[] GetBytes()     {         var sessionId = new byte[4];         Buffer.BlockCopy(_sessionId, 0, sessionId, 0, 4);         return sessionId;     } }<\/code><\/pre>\n<p>\u0414\u043e\u0436\u0434\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 <strong>Response<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 &#171;\u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432&#187; \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"cs\">public static class Response { \tpublic static byte ParseType(byte[] data) \t{ \t\treturn data[0]; \t}    \/\/  \tpublic static SessionId ParseSessionId(byte[] data) \t{ \t\tif (data.Length &lt; 1) throw new IncorrectPackageDataException(data); \t\tvar sessionIdBytes = new byte[4]; \t\tBuffer.BlockCopy(data, 1, sessionIdBytes, 0, 4); \t\treturn new SessionId(sessionIdBytes); \t}  \tpublic static byte[] ParseHandshake(byte[] data) \t{ \t\tif (data.Length &lt; 5) throw new IncorrectPackageDataException(data); \t\tvar response = BitConverter.GetBytes(int.Parse(Encoding.ASCII.GetString(data, 5, data.Length - 6))); \t\tif (BitConverter.IsLittleEndian) \t\t{ \t\t\tresponse = response.Reverse().ToArray(); \t\t}  \t\treturn response; \t}  \tpublic static ServerBasicState ParseBasicState(byte[] data) \t{ \t\tif (data.Length &lt;= 5) \t\t\tthrow new IncorrectPackageDataException(data);  \t\tvar statusValues = new Queue&lt;string&gt;(); \t\tshort port = -1;  \t\tdata = data.Skip(5).ToArray(); \/\/ Skip Type + SessionId \t\tvar stream = new MemoryStream(data);  \t\tvar sb = new StringBuilder(); \t\tint currentByte; \t\tint counter = 0; \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (counter &gt; 6) break;        \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043d\u043e\u0440\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430 \t\t\tif (counter == 5) \t\t\t{ \t\t\t\tbyte[] portBuffer = {(byte) currentByte, (byte) stream.ReadByte()}; \t\t\t\tif (!BitConverter.IsLittleEndian) \t\t\t\t\tportBuffer = portBuffer.Reverse().ToArray();  \t\t\t\tport = BitConverter.ToInt16(portBuffer); \/\/ Little-endian short \t\t\t\tcounter++;  \t\t\t\tcontinue; \t\t\t}        \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b-\u0441\u0442\u0440\u043e\u043a\u0438 \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tstring fieldValue = sb.ToString(); \t\t\t\tstatusValues.Enqueue(fieldValue); \t\t\t\tsb.Clear(); \t\t\t\tcounter++; \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tvar serverInfo = new ServerBasicState \t\t{ \t\t\tMotd = statusValues.Dequeue(), \t\t\tGameType = statusValues.Dequeue(), \t\t\tMap = statusValues.Dequeue(), \t\t\tNumPlayers = int.Parse(statusValues.Dequeue()), \t\t\tMaxPlayers = int.Parse(statusValues.Dequeue()), \t\t\tHostPort = port, \t\t\tHostIp = statusValues.Dequeue(), \t\t};  \t\treturn serverInfo; \t}    \/\/ \"\u0421\u0435\u043a\u0446\u0438\u0438\" \u043f\u0430\u043a\u0435\u0442\u0430 \u0440\u0435\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u0430\u0439\u0442,   \/\/ \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0447\u0442\u043e \u043c\u044b \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \tpublic static ServerFullState ParseFullState(byte[] data) \t{ \t\tvar statusKeyValues = new Dictionary&lt;string, string&gt;(); \t\tvar players = new List&lt;string&gt;();  \t\tvar buffer = new byte[256]; \t\tStream stream = new MemoryStream(data);  \t\tstream.Read(buffer, 0, 5); \/\/ Read Type + SessionID \t\tstream.Read(buffer, 0, 11); \/\/ Padding: 11 bytes constant \t\tvar constant1 = new byte[] {0x73, 0x70, 0x6C, 0x69, 0x74, 0x6E, 0x75, 0x6D, 0x00, 0x80, 0x00}; \t\tfor (int i = 0; i &lt; constant1.Length; i++) \t\t\tDebug.Assert(constant1[i] == buffer[i], \"Byte mismatch at \" + i + \" Val :\" + buffer[i]);  \t\tvar sb = new StringBuilder(); \t\tstring lastKey = string.Empty; \t\tint currentByte; \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tif (!string.IsNullOrEmpty(lastKey)) \t\t\t\t{ \t\t\t\t\tstatusKeyValues.Add(lastKey, sb.ToString()); \t\t\t\t\tlastKey = string.Empty; \t\t\t\t} \t\t\t\telse \t\t\t\t{ \t\t\t\t\tlastKey = sb.ToString(); \t\t\t\t\tif (string.IsNullOrEmpty(lastKey)) break; \t\t\t\t}  \t\t\t\tsb.Clear(); \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tstream.Read(buffer, 0, 10); \/\/ Padding: 10 bytes constant \t\tvar constant2 = new byte[] {0x01, 0x70, 0x6C, 0x61, 0x79, 0x65, 0x72, 0x5F, 0x00, 0x00}; \t\tfor (int i = 0; i &lt; constant2.Length; i++) \t\t\tDebug.Assert(constant2[i] == buffer[i], \"Byte mismatch at \" + i + \" Val :\" + buffer[i]);  \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tvar player = sb.ToString(); \t\t\t\tif (string.IsNullOrEmpty(player)) break; \t\t\t\tplayers.Add(player); \t\t\t\tsb.Clear(); \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tServerFullState fullState = new() \t\t{ \t\t\tMotd = statusKeyValues[\"hostname\"], \t\t\tGameType = statusKeyValues[\"gametype\"], \t\t\tGameId = statusKeyValues[\"game_id\"], \t\t\tVersion = statusKeyValues[\"version\"], \t\t\tPlugins = statusKeyValues[\"plugins\"], \t\t\tMap = statusKeyValues[\"map\"], \t\t\tNumPlayers = int.Parse(statusKeyValues[\"numplayers\"]), \t\t\tMaxPlayers = int.Parse(statusKeyValues[\"maxplayers\"]), \t\t\tPlayerList = players.ToArray(), \t\t\tHostIp = statusKeyValues[\"hostip\"], \t\t\tHostPort = int.Parse(statusKeyValues[\"hostport\"]), \t\t};  \t\treturn fullState; \t} } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u0414\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/h2>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0442\u043e\u043c, \u043e \u0447\u0435\u043c \u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0432\u044b\u0448\u0435. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041a\u043e\u0434 \u0432\u0437\u044f\u0442 \u0438\u0437 \u043c\u043e\u0435\u0433\u043e <a href=\"https:\/\/github.com\/MaxLevs\/MCServerNotifier\" rel=\"noopener noreferrer nofollow\">\u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/a>. \u0417\u0434\u0435\u0441\u044c \u043a\u0430\u0436\u0434\u044b\u0435 5 \u0441\u0435\u043a\u0443\u043d\u0434 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f FullStatus, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c ChallengeToken  \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e. \u0412\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 2 \u0440\u0435\u0436\u0438\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b: \u0448\u0442\u0430\u0442\u043d\u044b\u0439 \u0438 \u0440\u0435\u0436\u0438\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u0448\u0442\u0430\u0442\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043a\u0435\u043d \u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 FullStatus. \u041f\u0440\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0443\u043f\u0430\u0432\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430\/\u043e\u0431\u043e\u0440\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\/etc (5 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438) \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0435\u0436\u0438\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438 \u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0448\u0442\u0430\u0442\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"cs\">public StatusWatcher(string serverName, string host, int queryPort) {     ServerName = serverName;     _mcQuery = new McQuery(Dns.GetHostAddresses(host)[0], queryPort);     _mcQuery.InitSocket(); }  public async Task Unwatch() {     await UpdateChallengeTokenTimer.DisposeAsync();     await UpdateServerStatusTimer.DisposeAsync(); }  public async void Watch() {   \t\/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c challengetoken \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443 \u043a\u0430\u0436\u0434\u044b\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434     UpdateChallengeTokenTimer = new Timer(async obj =&gt;     {         if (!IsOnline) return;                  if(Debug)             Console.WriteLine($\"[INFO] [{ServerName}] Send handshake request\");          try         {             var challengeToken = await _mcQuery.GetHandshake();                        \t\/\/ \u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u043e\u043a, \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0432 \u043e\u043d\u043b\u0430\u0439\u043d\u0435 \u0438 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043f\u043e\u043f\u044b\u0442\u043e\u043a             IsOnline = true;           \t             lock (_retryCounterLock)             {                 RetryCounter = 0;             }                          if(Debug)                 Console.WriteLine($\"[INFO] [{ServerName}] ChallengeToken is set up: \" + BitConverter.ToString(challengeToken));         }                \t\/\/ \u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a         catch (Exception ex)         {             if (ex is SocketException || ex is McQueryException || ex is ChallengeTokenIsNullException)             {                 if(Debug)                     Console.WriteLine($\"[WARNING] [{ServerName}] [UpdateChallengeTokenTimer] Server doesn't response. Try to reconnect: {RetryCounter}\");                 if(ex is McQueryException)                     Console.Error.WriteLine(ex);                                  lock (_retryCounterLock)                 {                     RetryCounter++;                     if (RetryCounter &gt;= RetryMaxCount)                     {                         RetryCounter = 0;                         WaitForServerAlive(); \/\/ \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0440\u0435\u0436\u0438\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f                     }                 }             }              else             {                 throw;             }         }              }, null, 0, GettingChallengeTokenInterval);               \t\/\/ \u041f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435     UpdateServerStatusTimer = new Timer(async obj =&gt;     {         if (!IsOnline) return;                  if(Debug)             Console.WriteLine($\"[INFO] [{ServerName}] Send full status request\");          try         {             var response = await _mcQuery.GetFullStatus();                          IsOnline = true;             lock (_retryCounterLock)             {                 RetryCounter = 0;             }                          if(Debug)                 Console.WriteLine($\"[INFO] [{ServerName}] Full status is received\");                          OnFullStatusUpdated?.Invoke(this, new ServerStateEventArgs(ServerName, response));         }                \t\/\/ \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c         catch (Exception ex)         {             if (ex is SocketException || ex is McQueryException || ex is ChallengeTokenIsNullException)             {                 if(Debug)                     Console.WriteLine($\"[WARNING] [{ServerName}] [UpdateServerStatusTimer] Server doesn't response. Try to reconnect: {RetryCounter}\");                 if(ex is McQueryException)                     Console.Error.WriteLine(ex);                                  lock (_retryCounterLock)                 {                     RetryCounter++;                     if (RetryCounter &gt;= RetryMaxCount)                     {                         RetryCounter = 0;                         WaitForServerAlive();                     }                 }             }                          else             {                 throw;             }         }              }, null, 500, GettingStatusInterval); }<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0445\u043e\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0445\u044d\u043d\u0434\u0448\u0435\u0439\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e ChallengeToken.<\/p>\n<pre><code class=\"cs\">public async void WaitForServerAlive() {     if(Debug)         Console.WriteLine($\"[WARNING] [{ServerName}] Server is unavailable. Waiting for reconnection...\");    \t\/\/ \u041e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435     IsOnline = false;     await Unwatch();      _mcQuery.InitSocket(); \/\/ \u041f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043e\u043a\u0435\u0442      Timer waitTimer = null;     waitTimer = new Timer(async obj =&gt; {         try         {             await _mcQuery.GetHandshake();            \t\/\/ \u0413\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u0448\u0442\u0430\u0442\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440             IsOnline = true;             Watch();             lock (_retryCounterLock)             {                 RetryCounter = 0;             }              waitTimer.Dispose();         }              \t\/\/ \u041f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u043a\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0435 5 (\u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f) \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439         catch (SocketException)         {             if(Debug)                 Console.WriteLine($\"[WARNING] [{ServerName}] [WaitForServerAlive] Server doesn't response. Try to reconnect: {RetryCounter}\");              lock (_retryCounterLock)             {                 RetryCounter++;                 if (RetryCounter &gt;= RetryMaxCount)                 {                     if(Debug)                         Console.WriteLine($\"[WARNING] [{ServerName}] [WaitForServerAlive] Recreate socket\");                      RetryCounter = 0;                     _mcQuery.InitSocket();                 }             }         }     }, null, 500, 5000); }<\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/543798\/\"> https:\/\/habr.com\/ru\/post\/543798\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>Minecraft Server Query<\/strong> \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0443\u0442\u0451\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0430\u0440\u044b-\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0435\u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u044b\u0445 UDP-\u043f\u0430\u043a\u0435\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430 <a href=\"https:\/\/wiki.vg\/Query\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u043a\u0438<\/a> \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0440\u0430\u0437\u0438\u043b\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0443\u0446\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f .Net \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041f\u043e\u0438\u0441\u043a\u0430\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043b\u0438\u0431\u043e \u0438\u043c\u0435\u043b\u0438 \u0443\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u0445\u043e\u0442\u044f, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043a\u0443\u0434\u0430 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u0440\u0435\u0437\u0430\u0442\u044c-\u0442\u043e.<\/p>\n<p>\u0422\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<h2>\u0421\u043a\u0430\u0436\u0438 \u043c\u043d\u0435, \u043a\u0442\u043e \u0442\u044b&#8230;<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0430\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b Minecraft Query. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/wiki.vg\/Query\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u043a\u0438<\/a>, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432 \u0440\u0430\u0441\u043f\u043e\u0440\u044f\u0436\u0435\u043d\u0438\u0438 3 \u0432\u0438\u0434\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, 3 \u0432\u0438\u0434\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>Handshake<\/p>\n<\/li>\n<li>\n<p>BasicStatus<\/p>\n<\/li>\n<li>\n<p>FullStatus<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0442\u0438\u043f \u043f\u0430\u043a\u0435\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f <strong>ChallengeToken<\/strong>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0432\u0443\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u041f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043d \u043a IP-\u0430\u0434\u0440\u0435\u0441\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u043d\u0430 <strong>30 \u0441\u0435\u043a\u0443\u043d\u0434<\/strong>. \u0421\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0434\u0432\u0443\u0445 \u044f\u0441\u043d\u0430 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430 \u043b\u0438\u0448\u044c \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u043d\u0446\u0430\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u043c\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0442\u0432\u0435\u0442 BasicStatus<\/p>\n<figure class=\"\"><figcaption>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 BasicStatus<\/figcaption><\/figure>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u2013 FullStatus<\/p>\n<figure class=\"full-width\"><figcaption>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 FullStatus<\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u043e\u043c\u0438\u043c\u043e \u0442\u0435\u0445, \u0447\u0442\u043e \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 short, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 <em>big-endian<\/em>. \u0410 \u0434\u043b\u044f \u043f\u043e\u043b\u044f <strong>SessionId<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <em>SessionId &amp; 0x0F0F0F0F == SessionId<\/em>.<\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<figure class=\"\"><figcaption>\u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435<\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 \u0432\u0438\u043a\u0438.<\/p>\n<h2>\u0418 \u044f \u0441\u043a\u0430\u0436\u0443 \u0442\u0435\u0431\u0435, \u043a\u0430\u043a \u0442\u0435\u0431\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435. \u0413\u043e\u0442\u043e\u0432\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c API \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0437 3 \u0432\u0438\u0434\u043e\u0432 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0440\u0430\u0441\u043f\u0430\u0440\u0448\u0435\u043d\u043e\u043c \u0432\u0438\u0434\u0435. <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u044f \u0445\u043e\u0447\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u044b \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0436\u0438\u0437\u043d\u0435\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f <strong>ChallengeToken<\/strong>. \u0415\u0441\u043b\u0438 \u044f \u0431\u0443\u0434\u0443 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 3 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0442\u043e \u044f \u043d\u0435 \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u043e\u0441\u044c \u0434\u0432\u0430: \u0445\u044d\u043d\u0434\u0448\u0435\u0439\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 \u044f \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0437 \u0432 \u0447\u0430\u0441, \u0437\u0430\u0447\u0435\u043c \u043c\u043d\u0435 \u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a\u0430\u0436\u0434\u044b\u0435 30 \u0441\u0435\u043a\u0443\u043d\u0434? \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 &#171;\u0440\u0443\u0447\u043d\u043e\u043c&#187; \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0432\u0448\u0438\u0441\u044c, \u043c\u043e\u0436\u0435\u043c \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u042f \u0432\u0438\u0436\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code class=\"cs\">public static async Task&lt;ServerState&gt; DoSomething(IPAddress host, int port) { \tvar mcQuery = new McQuery(host, port);   mcQuery.InitSocket();   await mcQuery.GetHandshake();   return await mcQuery.GetFullStatus(); }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0440\u0430\u0437\u043e\u0432\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0414\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e (\u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438).<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u043a\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <strong>Request<\/strong>.<\/p>\n<pre><code class=\"cs\">public class Request { \t\t\/\/ \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430     private static readonly byte[] Magic = { 0xfe, 0xfd };     private static readonly byte[] Challenge = { 0x09 };     private static readonly byte[] Status = { 0x00 };        public byte[] Data { get; private set; }          private Request(){}      public byte RequestType =&gt; Data[2];      public static Request GetHandshakeRequest(SessionId sessionId)     {         var request = new Request();                \t\/\/ \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442         var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Challenge);         data.AddRange(sessionId.GetBytes());                  request.Data = data.ToArray();         return request;     }      public static Request GetBasicStatusRequest(SessionId sessionId, byte[] challengeToken)     {         if (challengeToken == null)         {             throw new ChallengeTokenIsNullException();         }                      var request = new Request();                  var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Status);         data.AddRange(sessionId.GetBytes());         data.AddRange(challengeToken);                  request.Data = data.ToArray();         return request;     }          public static Request GetFullStatusRequest(SessionId sessionId, byte[] challengeToken)     {         if (challengeToken == null)         {             throw new ChallengeTokenIsNullException();         }                  var request = new Request();                  var data = new List&lt;byte&gt;();         data.AddRange(Magic);         data.AddRange(Status);         data.AddRange(sessionId.GetBytes());         data.AddRange(challengeToken);         data.AddRange(new byte[] {0x00, 0x00, 0x00, 0x00}); \/\/ Padding                  request.Data = data.ToArray();         return request;     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e. \u0425\u0440\u0430\u043d\u0438\u043c \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u0432 \u0442\u0440\u0451\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445. \u041c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <strong>SessionId<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435, \u0442\u0430\u043a \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"cs\">public class SessionId {     private readonly byte[] _sessionId;      public SessionId (byte[] sessionId)     {         _sessionId = sessionId;     }  \t\t\/\/ \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 SessionId     public static SessionId GenerateRandomId()     {         var sessionId = new byte[4];         new Random().NextBytes(sessionId);         sessionId = sessionId.Select(@byte =&gt; (byte)(@byte &amp; 0x0F)).ToArray();         return new SessionId(sessionId);     }      public string GetString()     {         return BitConverter.ToString(_sessionId);     }      public byte[] GetBytes()     {         var sessionId = new byte[4];         Buffer.BlockCopy(_sessionId, 0, sessionId, 0, 4);         return sessionId;     } }<\/code><\/pre>\n<p>\u0414\u043e\u0436\u0434\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u043a\u043b\u0430\u0441\u0441 <strong>Response<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 &#171;\u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432&#187; \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"cs\">public static class Response { \tpublic static byte ParseType(byte[] data) \t{ \t\treturn data[0]; \t}    \/\/  \tpublic static SessionId ParseSessionId(byte[] data) \t{ \t\tif (data.Length &lt; 1) throw new IncorrectPackageDataException(data); \t\tvar sessionIdBytes = new byte[4]; \t\tBuffer.BlockCopy(data, 1, sessionIdBytes, 0, 4); \t\treturn new SessionId(sessionIdBytes); \t}  \tpublic static byte[] ParseHandshake(byte[] data) \t{ \t\tif (data.Length &lt; 5) throw new IncorrectPackageDataException(data); \t\tvar response = BitConverter.GetBytes(int.Parse(Encoding.ASCII.GetString(data, 5, data.Length - 6))); \t\tif (BitConverter.IsLittleEndian) \t\t{ \t\t\tresponse = response.Reverse().ToArray(); \t\t}  \t\treturn response; \t}  \tpublic static ServerBasicState ParseBasicState(byte[] data) \t{ \t\tif (data.Length &lt;= 5) \t\t\tthrow new IncorrectPackageDataException(data);  \t\tvar statusValues = new Queue&lt;string&gt;(); \t\tshort port = -1;  \t\tdata = data.Skip(5).ToArray(); \/\/ Skip Type + SessionId \t\tvar stream = new MemoryStream(data);  \t\tvar sb = new StringBuilder(); \t\tint currentByte; \t\tint counter = 0; \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (counter &gt; 6) break;        \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043d\u043e\u0440\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430 \t\t\tif (counter == 5) \t\t\t{ \t\t\t\tbyte[] portBuffer = {(byte) currentByte, (byte) stream.ReadByte()}; \t\t\t\tif (!BitConverter.IsLittleEndian) \t\t\t\t\tportBuffer = portBuffer.Reverse().ToArray();  \t\t\t\tport = BitConverter.ToInt16(portBuffer); \/\/ Little-endian short \t\t\t\tcounter++;  \t\t\t\tcontinue; \t\t\t}        \/\/ \u041f\u0430\u0440\u0441\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b-\u0441\u0442\u0440\u043e\u043a\u0438 \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tstring fieldValue = sb.ToString(); \t\t\t\tstatusValues.Enqueue(fieldValue); \t\t\t\tsb.Clear(); \t\t\t\tcounter++; \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tvar serverInfo = new ServerBasicState \t\t{ \t\t\tMotd = statusValues.Dequeue(), \t\t\tGameType = statusValues.Dequeue(), \t\t\tMap = statusValues.Dequeue(), \t\t\tNumPlayers = int.Parse(statusValues.Dequeue()), \t\t\tMaxPlayers = int.Parse(statusValues.Dequeue()), \t\t\tHostPort = port, \t\t\tHostIp = statusValues.Dequeue(), \t\t};  \t\treturn serverInfo; \t}    \/\/ \"\u0421\u0435\u043a\u0446\u0438\u0438\" \u043f\u0430\u043a\u0435\u0442\u0430 \u0440\u0435\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u0430\u0439\u0442,   \/\/ \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0447\u0442\u043e \u043c\u044b \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \tpublic static ServerFullState ParseFullState(byte[] data) \t{ \t\tvar statusKeyValues = new Dictionary&lt;string, string&gt;(); \t\tvar players = new List&lt;string&gt;();  \t\tvar buffer = new byte[256]; \t\tStream stream = new MemoryStream(data);  \t\tstream.Read(buffer, 0, 5); \/\/ Read Type + SessionID \t\tstream.Read(buffer, 0, 11); \/\/ Padding: 11 bytes constant \t\tvar constant1 = new byte[] {0x73, 0x70, 0x6C, 0x69, 0x74, 0x6E, 0x75, 0x6D, 0x00, 0x80, 0x00}; \t\tfor (int i = 0; i &lt; constant1.Length; i++) \t\t\tDebug.Assert(constant1[i] == buffer[i], \"Byte mismatch at \" + i + \" Val :\" + buffer[i]);  \t\tvar sb = new StringBuilder(); \t\tstring lastKey = string.Empty; \t\tint currentByte; \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tif (!string.IsNullOrEmpty(lastKey)) \t\t\t\t{ \t\t\t\t\tstatusKeyValues.Add(lastKey, sb.ToString()); \t\t\t\t\tlastKey = string.Empty; \t\t\t\t} \t\t\t\telse \t\t\t\t{ \t\t\t\t\tlastKey = sb.ToString(); \t\t\t\t\tif (string.IsNullOrEmpty(lastKey)) break; \t\t\t\t}  \t\t\t\tsb.Clear(); \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tstream.Read(buffer, 0, 10); \/\/ Padding: 10 bytes constant \t\tvar constant2 = new byte[] {0x01, 0x70, 0x6C, 0x61, 0x79, 0x65, 0x72, 0x5F, 0x00, 0x00}; \t\tfor (int i = 0; i &lt; constant2.Length; i++) \t\t\tDebug.Assert(constant2[i] == buffer[i], \"Byte mismatch at \" + i + \" Val :\" + buffer[i]);  \t\twhile ((currentByte = stream.ReadByte()) != -1) \t\t{ \t\t\tif (currentByte == 0x00) \t\t\t{ \t\t\t\tvar player = sb.ToString(); \t\t\t\tif (string.IsNullOrEmpty(player)) break; \t\t\t\tplayers.Add(player); \t\t\t\tsb.Clear(); \t\t\t} \t\t\telse sb.Append((char) currentByte); \t\t}  \t\tServerFullState fullState = new() \t\t{ \t\t\tMotd = statusKeyValues[\"hostname\"], \t\t\tGameType = statusKeyValues[\"gametype\"], \t\t\tGameId = statusKeyValues[\"game_id\"], \t\t\tVersion = statusKeyValues[\"version\"], \t\t\tPlugins = statusKeyValues[\"plugins\"], \t\t\tMap = statusKeyValues[\"map\"], \t\t\tNumPlayers = int.Parse(statusKeyValues[\"numplayers\"]), \t\t\tMaxPlayers = int.Parse(statusKeyValues[\"maxplayers\"]),<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318480","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318480"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318480\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}