diff --git a/Source/core/core/network/connection.h b/Source/core/core/network/connection.h index 9a2650c..8b7528c 100644 --- a/Source/core/core/network/connection.h +++ b/Source/core/core/network/connection.h @@ -91,11 +91,23 @@ namespace server } uint8* packet_data = wbuffer.write(packet->data, packet->length); + if (packet_data[0] == 'E') + { + printf("ready\n"); + } + //wbuffer.rpos = packet_data - wbuffer.data(); //wbuffer.rend = wbuffer.rpos + packet->length; //crossgate::xg_dispatch_packet(std::move(*packet)); - send_handler(wbuffer); + if (!packet->raw) + { + send_handler(wbuffer); + } + else + { + printf("send_raw:%s\n", packet_data); + } //std::string packet_str((char*)packet->data, packet->length); diff --git a/Source/core/core/network/packet_queue.h b/Source/core/core/network/packet_queue.h index 7767c8b..a307d13 100644 --- a/Source/core/core/network/packet_queue.h +++ b/Source/core/core/network/packet_queue.h @@ -8,6 +8,7 @@ namespace server { uint8* data; uint64 length; + bool raw; }; @@ -50,7 +51,7 @@ namespace server packet_queue() : state(0), read_state(0), write_state(0), frame{} {} - bool enqueue(uint8* packet_data, uint64 packet_size) + bool enqueue(uint8* packet_data, uint64 packet_size, bool raw = false) { this->begin_write(); @@ -64,7 +65,7 @@ namespace server if (buffer_space >= packet_size && packet_slots >= 1) { memcpy(&f.data[f.wpos], packet_data, packet_size); - f.packets[f.packet_count] = { &f.data[f.wpos], packet_size }; + f.packets[f.packet_count] = { &f.data[f.wpos], packet_size, raw }; f.wpos += packet_size; f.packet_count++; result = true; diff --git a/Source/xgmsv/crossgate/mmo_server.cpp b/Source/xgmsv/crossgate/mmo_server.cpp index 43f8dad..ff93240 100644 --- a/Source/xgmsv/crossgate/mmo_server.cpp +++ b/Source/xgmsv/crossgate/mmo_server.cpp @@ -104,6 +104,24 @@ namespace mmo_server void init(int argc, char** argv) { + /* + char* packet_de = "PBt-ztsrSCXizpHiNuKPg5AuyS6PzdstfC7blf3rb-Dbo7tf5NhhQ-+Pg4--7kE6qjGnMfl6th1N20udvQ"; + core::byte_buffer buf_de(4096); + buf_de.write(packet_de, strlen(packet_de)); + crossgate::decrypt_message(buf_de); + printf("string:\"%s\"\n", buf_de.data() + buf_de.rpos); + + exit(0); + //*/ + + //* + char packet[] = R"(IP 127.0.0.1 )"; + core::byte_buffer buf(4096); + buf.write(packet, sizeof(packet)); + crossgate::encrypt_message(buf); + printf("string:%s\n", buf.data()); + //*/ + std::map args_map = docopt::docopt(mmo_server::usage, { argv + 1, argv + argc }, true, "MMO Server 1.0"); if (args_map.empty()) { @@ -184,11 +202,6 @@ namespace mmo_server //char packet[] = "eyM3e-ijJJlKxYcGgBZ6mTVLyOrHj0jER2D05zIGSMJ-nAnIGGeYkS07zNl3FjzELZUalXxUVO3xRCNZhC2Pvv9MZXuxobNA7Gev-6awxQonbIWYB+eb"; //char packet[] = R"(CharList 0 jason|0\\z241400\\z1\\z15\\z0\\z0\\z0\\z15\\z0\\z0\\z100\\z0\\z12\\zjason\\z2\\z见习传教士\\z2\\z106002\\z-1| )"; /* - char packet_de[] = "FsV1lm6adLyZmHKaINgpnXWZnAmdIAg"; - core::byte_buffer buf_de(4096); - buf_de.write(packet_de, sizeof(packet_de) - 1); - crossgate::decrypt_message(buf_de); - printf("string:%s\n", buf_de.data()); char packet[] = "Echo nr "; core::byte_buffer buf(4096); diff --git a/Source/xgmsv/crossgate/xg_crypto.h b/Source/xgmsv/crossgate/xg_crypto.h index 1616ef9..c440378 100644 --- a/Source/xgmsv/crossgate/xg_crypto.h +++ b/Source/xgmsv/crossgate/xg_crypto.h @@ -328,18 +328,22 @@ namespace server decrypted_size--; // -1 for checksum decrypted_size = remove_salt(buffer, buffer, decrypted_size); - remove_conditional_bit_reverse(buffer, buffer, decrypted_size); uint8 workbuf[4096]; + remove_conditional_bit_reverse(workbuf, buffer, decrypted_size); + if (buffer[0] % 2) { - decrypted_size = decompress_message(workbuf, sizeof(workbuf), buffer + 1, decrypted_size); - memcpy(buffer, workbuf, decrypted_size); + decrypted_size = decompress_message(buffer, payload_size + payload.free_space(), workbuf + 1, decrypted_size); + } + else + { + memcpy(buffer, workbuf + 1, decrypted_size); } buffer[decrypted_size] = '\0'; - payload.rpos++; + //payload.rpos++; payload.rend += decrypted_size - payload_size; return true; } @@ -572,7 +576,8 @@ namespace server reg = (reg << 6); } } - if (reg) dst[byte_counter++] = table[(reg & 0b1111110000000000) >> (8 + 2)]; + /*if (reg) */ + dst[byte_counter++] = table[(reg & 0b1111110000000000) >> (8 + 2)]; // remainder dst[byte_counter] = '\0'; return byte_counter; } @@ -581,15 +586,15 @@ namespace server bool encrypt_message(core::byte_buffer& payload) { uint8* buffer = payload.data() + payload.rpos; - const uint64 payload_size = payload.rend - payload.rpos; + const uint64 payload_size_with_0 = payload.rend - payload.rpos; - if (payload.free_space() < payload_size) + if (payload.free_space() < payload_size_with_0) { printf("encrypt_message: not enough space\n"); return false; } - uint64 encrypted_size = payload_size + 1; // packet_length padding + uint64 encrypted_size = payload_size_with_0; char header = (char)encrypted_size; @@ -601,7 +606,7 @@ namespace server } uint8 workbuf[4096]; - encrypted_size = compress_message(workbuf, sizeof(workbuf), buffer, payload_size); + encrypted_size = compress_message(workbuf, sizeof(workbuf), buffer, payload_size_with_0 - 1); // compress without terminator /* char char9_str[] = { @@ -632,19 +637,19 @@ char char9_str[] = { } buffer[0] = header; + encrypted_size++; // header - encrypted_size++; // null terminator; uint8 workbuf[4096]; memset(workbuf, 0, 4096); - uint8 checksum = apply_conditional_bit_reverse(buffer, buffer, encrypted_size); - encrypted_size = apply_salt_and_add_checksum(workbuf, buffer, encrypted_size, checksum); + uint8 checksum = apply_conditional_bit_reverse(buffer, buffer, encrypted_size); // with terminator + encrypted_size = apply_salt_and_add_checksum(workbuf, buffer, encrypted_size, checksum); // terminator possibly consumed encrypted_size = util_256to64(buffer, workbuf, mapping_table, encrypted_size); buffer[encrypted_size] = '\n'; //buffer[encrypted_size] = '\0'; - payload.rend += encrypted_size - payload_size; + payload.rend += encrypted_size - payload_size_with_0; payload.wpos = payload.rend + 1; return true; } diff --git a/Source/xgmsv/crossgate/xg_session.cpp b/Source/xgmsv/crossgate/xg_session.cpp index 6977a4f..27601e6 100644 --- a/Source/xgmsv/crossgate/xg_session.cpp +++ b/Source/xgmsv/crossgate/xg_session.cpp @@ -58,7 +58,7 @@ namespace server auto inactive_seconds = std::chrono::duration_cast(core::server_time - session->last_active); - if (inactive_seconds.count() > 10) + if (inactive_seconds.count() > 60) { delete session; session = nullptr; @@ -85,7 +85,7 @@ namespace server void xg_session::handle_echo(xg_packet* packet) { - if (!send_raw(R"(Echo nr )")) + if (!send_msg(R"(Echo nr )")) { printf("handle_echo failed.\n"); } @@ -108,7 +108,7 @@ namespace server refuse = 2 }; - if (!send_raw(R"(ClientLogin 0 block )")) + if (!send_msg(R"(ClientLogin 0 block )")) { printf("handle_client_login failed.\n"); } @@ -133,46 +133,80 @@ namespace server wind = 10, earth = 11, water = 12, + login_times = 13, + name_again = 14, + soemthing2 = 15, + char_class = 16, + something3 = 17, + char_sprite = 18, + something4 = 19 }; - if (!send_raw(R"(CharList 0 rarecheese|0\\z241401\\z1\\z15\\z0\\z0\\z0\\z15\\z0\\z0\\z100\\z0\\z12\\zrarecheese\\z2\\z见习传教士\\z2\\z106002\\z-1| )")) - { - printf("handle_char_list failed.\n"); - } + send_msg(R"(PV 8 )"); + send_msg(R"(CharList 0 jason|0\\z241401\\z1\\z15\\z0\\z0\\z0\\z15\\z0\\z0\\z100\\z0\\z12\\zjason\\z2\\z见习传教士\\z2\\z106002\\z-1| )"); printf("handle_char_list!\n"); } void xg_session::handle_char_login(xg_packet* packet) { - send_raw(R"(PRV 3|5|100|0 )"); - send_raw(R"(CharLogin successful )"); - send_raw(R"(LI 3I3 1JayvY 1 0 )"); - send_raw(R"(CC 0 hV p J c 6 0 0 0 0 -1 )"); - send_raw(R"(MN 城西医院\\z0 )"); - send_raw(R"(CP 1|155|155|185|185|15|0|0|0|15|50|50|50|0|16|1|23|23|23|107|107|60|100|100|0|0|0|5000|0|rarecheese|| )"); - send_raw(R"(CP2 1|0|0|0|0|0|0|0|0|0|0|100|0|0|0|0|241400|10|100| )"); - send_raw(R"(CJ 1 见习传教士 )"); - send_raw(R"(CS 0|||||||||||1|||||||||||2|||||||||||3|||||||||||4|||||||||||5|||||||||||6|||||||||||7|||||||||||8|||||||||||9|||||||||||10|||||||||||11|||||||||||12|||||||||||13|||||||||||14||||||||||| )"); - send_raw(R"(TITLE 敬畏的寂静|0|17|见习传教士|1|161|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); - send_raw(R"(I 7|出生水晶|0|$4等级\S1\\n$4耐久\S1000/1000\S$0类别\S水晶\\n\\n\\n\\n\\n\\n\\n$4初期装备的水晶\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|27511|1|2|0|1|184|9200|22|0||8|沾着泪水的信|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|26579|1|0|0|1|56|22238|26|0||9|时间水晶Lv6|0|$4等级\S1\\n$4耐久\S0001/0001\S$0类别\S未知\\n能恢复作业时间的水晶,恢复后的小时数与水晶等级相等。\\n\\n\\n\\n\\n$4能恢复作业时间的水 晶,恢复后的小时数与水晶等级相等。\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|99123|1|0|0|1|56|22693|26|1||10| 随意工作卡|0|$4等级\S1\\n$4耐久\S0005/0005\S$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4\\n\\n|27487|1|0|0|1|25|22022|26|0||11|生命回复药水(200)|0|$4等级\S3\\n$0类别\S药品\\n恢复目标生命值约200点\\n\\n\\n\\n\\n\\n$4回复生命力200点的药\\n\\n|26218|1|1|93|3|25|15608|43|20||12|传送羽毛-西医|0|$4等级\S1\\n$4耐久\S0004/0005\S$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4瞬间就传送到西医院的神奇羽毛。\\n\\n|27828|1|0|0|1|25|18779|26|0||13|僧侣适性检查合格证|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4传教士职业的就职推荐信\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|27881|0|0|0|1|56|18106|26|0||14|报酬的银币|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4法兰王国的银币\S\S\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|26573|0|0|72|1|56|18786|26|0| )"); - send_raw(R"(EP 0 0 )"); - send_raw(R"(KP 0 1|101321|4|93|93|99|99|1|16|1|48|40|34|101|100|24|0|40|60|0|10|1|新手红螳螂||0|0| )"); - send_raw(R"(KP2 0 1|2|9|4|5|3|25|0|45|-10|0|0|0|0|0|0|1| )"); - send_raw(R"(PT 0 0|7300|攻击|能以普通物理攻击给与打击|0|1|1141|0|1|7400|防御|能防守来自物理攻击的打击|0|1|72|1|2|407|气功弹\SLV8|给予对象前后列位置一体或数体的伤害,依等级改变攻击数。|40|1|117|2|3|1238|明净止水-Ⅴ|集中精神回复一定比例的体力,技 能和最大生命值越高回复比例上限越高(注意和回复力无关),使用后将无法闪躲物理攻击。\S|135|1|72|3| )"); - send_raw(R"(FS 0 )"); - send_raw(R"(MC 0 hV 0 0 p k bFX agh 0 )"); - send_raw(R"(AB ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); - send_raw(R"(ABG ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); - send_raw(R"(C 1|3I3|12|6|0|106002|1|0|rarecheese|\\z\\z|0|0|0|敬畏的寂静|0 )"); - send_raw(R"(C 2|1tq|10|5|4|14088|1|0|伯舒医师|\\z\\z|0|0|0||0 37|1ty|10|17|4|14088|1|0|姆涅医师|\\z\\z|0|0|0||0 2|1ti|12|5|4|14090|1|0|实习药剂师吉可|\\z\\z|0|0|0||0 29|1xH|16|9|6|14151|1|0|实习生蜜雅|\\z\\z|0|0|0||0 )"); - send_raw(R"(BT 5Co 0 )"); - send_raw(R"(POS 0 )"); - send_raw(R"(AL 1 0|0|0|0|0|0|0|0|0|0| )"); - send_raw(R"(IP 127.0.0.1 )"); - send_raw(R"(MAC Y O )"); - send_raw(R"(EF 0 0 )"); - send_raw(R"(TK -1 P|欢迎来到芝士的魔力宝贝服务器~ 4 0 )"); + send_raw(R"(EJQ35XO0sXyvF5j6Y2HPBZM)"); + //send_msg(R"(PRV 3|5|100|0 )"); + + send_msg(R"(CharLogin successful )"); + + send_msg(R"(LI 3H9 1JbdtH 1 0 )"); + + send_msg(R"(CC 0 hV p J c 6 0 0 0 0 -1 )"); + + send_msg(R"(MN 城西医院\\z0 )"); + + send_msg(R"(CP 1|155|155|185|185|15|0|0|0|15|50|50|50|0|16|1|23|23|23|107|107|60|100|100|0|0|0|5000|0|jason|| )"); + + send_msg(R"(CP2 1|0|0|0|0|0|0|0|0|0|0|100|0|0|0|0|241400|10|100| )"); + + send_msg(R"(CJ 1 见习传教士 )"); + + //send_msg(R"(CS 0|||||||||||1|||||||||||2|||||||||||3|||||||||||4|||||||||||5|||||||||||6|||||||||||7|||||||||||8|||||||||||9|||||||||||10|||||||||||11|||||||||||12|||||||||||13|||||||||||14||||||||||| )"); + + //send_msg(R"(TITLE 敬畏的寂静|0|17|见习传教士|1|161|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); + + //send_msg(R"(I 7|出生水晶|0|$4等级\S1\\n$4耐久\S1000/1000\S$0类别\S水晶\\n\\n\\n\\n\\n\\n\\n$4初期装备的水晶\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|27511|1|2|0|1|184|9200|22|0||8|沾着泪水的信|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|26579|1|0|0|1|56|22238|26|0||9|时间水晶Lv6|0|$4等级\S1\\n$4耐久\S0001/0001\S$0类别\S未知\\n能恢复作业时间的水晶,恢复后的小时数与水晶等级相等。\\n\\n\\n\\n\\n$4能恢复作业时间的水 晶,恢复后的小时数与水晶等级相等。\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|99123|1|0|0|1|56|22693|26|1||10| 随意工作卡|0|$4等级\S1\\n$4耐久\S0005/0005\S$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4\\n\\n|27487|1|0|0|1|25|22022|26|0||11|生命回复药水(200)|0|$4等级\S3\\n$0类别\S药品\\n恢复目标生命值约200点\\n\\n\\n\\n\\n\\n$4回复生命力200点的药\\n\\n|26218|1|1|93|3|25|15608|43|20||12|传送羽毛-西医|0|$4等级\S1\\n$4耐久\S0004/0005\S$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4瞬间就传送到西医院的神奇羽毛。\\n\\n|27828|1|0|0|1|25|18779|26|0||13|僧侣适性检查合格证|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4传教士职业的就职推荐信\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|27881|0|0|0|1|56|18106|26|0||14|报酬的银币|0|$4等级\S1\\n$0类别\S未知\\n\\n\\n\\n\\n\\n\\n$4法兰王国的银币\S\S\\n\\n$1放地上便会消失\S\\n$1无法用宠物邮件发送\S\\n|26573|0|0|72|1|56|18786|26|0| )"); + + send_msg(R"(EP 0 0 )"); + + //send_msg(R"(KP 0 1|101321|4|93|93|99|99|1|16|1|48|40|34|101|100|24|0|40|60|0|10|1|新手红螳螂||0|0| )"); + + //send_msg(R"(KP2 0 1|2|9|4|5|3|25|0|45|-10|0|0|0|0|0|0|1| )"); + + //send_msg(R"(PT 0 0|7300|攻击|能以普通物理攻击给与打击|0|1|1141|0|1|7400|防御|能防守来自物理攻击的打击|0|1|72|1|2|407|气功弹\SLV8|给予对象前后列位置一体或数体的伤害,依等级改变攻击数。|40|1|117|2|3|1238|明净止水-Ⅴ|集中精神回复一定比例的体力,技 能和最大生命值越高回复比例上限越高(注意和回复力无关),使用后将无法闪躲物理攻击。\S|135|1|72|3| )"); + + send_msg(R"(FS 0 )"); + + send_msg(R"(MC 0 hV 0 0 p k bFX agh 0 )"); + + //send_msg(R"(AB ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); + + //send_msg(R"(ABG ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| )"); + + send_raw(R"(PBt-ztsrSCXizpHiNuKPg5AuyS6PzdstfC7blf3rb-Dbo7tf5NhhQ-+Pg4--7kE6qjGnMfl6th1N20udvQ)"); + //send_msg(R"(C 1|3H9|12|6|0|106002|1|0|jason|\\z\\z|0|0|0|见习传教士|0 )"); + + send_msg(R"(C 2|1tq|10|5|4|14088|1|0|伯舒医师|\\z\\z|0|0|0||0 37|1ty|10|17|4|14088|1|0|姆涅医师|\\z\\z|0|0|0||0 2|1ti|12|5|4|14090|1|0|实习药剂师吉可|\\z\\z|0|0|0||0 29|1xH|16|9|6|14151|1|0|实习生蜜雅|\\z\\z|0|0|0||0 )"); + + send_msg(R"(BT 5Co 0 )"); + send_msg(R"(POS 0 )"); + send_msg(R"(AL 1 0|0|0|0|0|0|0|0|0|0| )"); + send_msg(R"(IP 127.0.0.1 )"); + send_msg(R"(MAC Y O )"); + send_msg(R"(EF 0 0 )"); + send_msg(R"(TK -1 P|欢迎来到芝士的魔力宝贝服务器~ 4 0 )"); + send_msg(R"(CA 3H9|12|6|0|0 )"); + + core::async_after(1s, + [this]() + { + }); /* send_raw(R"(TK -1 P|感谢购买大灰狼魔力。wow335.taobao.com 4 0 )"); send_raw(R"(TK -1 P|[版本申明]GMSV\SAvaritia\SFeb\S\S1\S2014\S共享版 4 0 )"); @@ -188,12 +222,12 @@ namespace server void xg_session::handle_char_logout(xg_packet* packet) { - send_raw(R"(CharLogout successful )"); + send_msg(R"(CharLogout successful )"); printf("handle_char_logout!\n"); - signal.fire(core::signal_code::shutdown); + //signal.fire(core::signal_code::shutdown); - marked_for_delete = true; + //marked_for_delete = true; } } diff --git a/Source/xgmsv/crossgate/xg_session.h b/Source/xgmsv/crossgate/xg_session.h index 9ee9195..b90f78e 100644 --- a/Source/xgmsv/crossgate/xg_session.h +++ b/Source/xgmsv/crossgate/xg_session.h @@ -56,9 +56,9 @@ namespace server signal.fire(core::signal_code::shutdown); } - bool enqueue_response(uint8* packet_data, uint32 packet_size) + bool enqueue_response(uint8* packet_data, uint32 packet_size, bool raw = false) { - if (!wqueue.enqueue(packet_data, packet_size)) + if (!wqueue.enqueue(packet_data, packet_size, raw)) { assert(false); printf("enqueue failed.\n"); @@ -70,7 +70,8 @@ namespace server return true; } -#define send_raw(str) enqueue_response((uint8*)str, sizeof(str) - 1) +#define send_msg(str) enqueue_response((uint8*)str, sizeof(str)) +#define send_raw(str) enqueue_response((uint8*)str "\n", sizeof(str), true) void handle_echo(xg_packet* packet);