diff --git a/plugins/bank/Makefile b/plugins/bank/Makefile index 58e4c16..5041f44 100755 --- a/plugins/bank/Makefile +++ b/plugins/bank/Makefile @@ -97,6 +97,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -120,7 +123,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : bank_init.o bank_logic.o bank_proto_buf.o bank_db.o bank_info.o fcgimodule.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/bank/bank_logic.cc b/plugins/bank/bank_logic.cc index b7085f0..32f2eab 100755 --- a/plugins/bank/bank_logic.cc +++ b/plugins/bank/bank_logic.cc @@ -89,7 +89,7 @@ bool Banklogic::OnBankMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/base.mk b/plugins/base.mk index bbc9b64..def4111 100644 --- a/plugins/base.mk +++ b/plugins/base.mk @@ -7,9 +7,9 @@ CPPFLAGS= CC=g++ MAKE=gmake #星云 -#PROJECT="STAR_CLOUD" +PROJECT="STAR_CLOUD" #默认星享 -PROJECT="" +#PROJECT="" diff --git a/plugins/circle/Makefile b/plugins/circle/Makefile index 3adc034..5376453 100755 --- a/plugins/circle/Makefile +++ b/plugins/circle/Makefile @@ -77,6 +77,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -99,7 +102,7 @@ time.o : $(USER_DIR)/logic/time.cc $(USER_DIR)/logic/time.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/time.cc $(INCLUDE_PATHS) $(PLUGIN) : circle_init.o circle_logic.o circle_db.o circle_info.o schduler_engine.o kafka.o \ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a \ $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CUSTOM_THIRD_PATH)/librdkafka/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -liconv -lmysqlclient -lqiniu \ diff --git a/plugins/circle/circle_logic.cc b/plugins/circle/circle_logic.cc index f5cd07b..95dede7 100755 --- a/plugins/circle/circle_logic.cc +++ b/plugins/circle/circle_logic.cc @@ -113,6 +113,7 @@ bool Circlelogic::OnCircleMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/comments/Makefile b/plugins/comments/Makefile index fb1b6b2..6c3fb62 100755 --- a/plugins/comments/Makefile +++ b/plugins/comments/Makefile @@ -94,6 +94,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -117,7 +120,7 @@ xml_parser.o : $(USER_DIR)/logic/xml_parser.cc $(USER_DIR)/logic/xml_parser.h $(PLUGIN) : comments_init.o comments_logic.o schduler_engine.o comments_proto_buf.o comments_redis.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient \ $^ -o $@ diff --git a/plugins/comments/comments_logic.cc b/plugins/comments/comments_logic.cc index 82540ab..7f1f16e 100755 --- a/plugins/comments/comments_logic.cc +++ b/plugins/comments/comments_logic.cc @@ -78,7 +78,7 @@ bool Commentslogic::OnCommentsMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/flashsale/Makefile b/plugins/flashsale/Makefile index 020abec..35d374d 100755 --- a/plugins/flashsale/Makefile +++ b/plugins/flashsale/Makefile @@ -104,6 +104,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -126,7 +129,7 @@ time.o : $(USER_DIR)/logic/time.cc $(USER_DIR)/logic/time.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/time.cc $(INCLUDE_PATHS) $(PLUGIN) : flash_init.o flash_logic.o flash_db.o share_memory.o flash_info.o flash_kafka.o schduler_engine.o \ - star_infos.o time.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o time.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CUSTOM_THIRD_PATH)/librdkafka/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient \ $^ -o $@ diff --git a/plugins/flashsale/flash_logic.cc b/plugins/flashsale/flash_logic.cc index 0ea2bc0..7de1e8e 100755 --- a/plugins/flashsale/flash_logic.cc +++ b/plugins/flashsale/flash_logic.cc @@ -111,6 +111,7 @@ bool Flashlogic::OnFlashMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/history/Makefile b/plugins/history/Makefile index 40643a0..a655372 100755 --- a/plugins/history/Makefile +++ b/plugins/history/Makefile @@ -97,6 +97,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -120,7 +123,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : history_init.o history_logic.o schduler_engine.o history_proto_buf.o history_db.o history_info.o fcgimodule.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/history/history_logic.cc b/plugins/history/history_logic.cc index 4c6b80a..5231ec9 100755 --- a/plugins/history/history_logic.cc +++ b/plugins/history/history_logic.cc @@ -94,7 +94,7 @@ bool Historylogic::OnHistoryMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/imcloud/Makefile b/plugins/imcloud/Makefile index 3e01eb0..9f0f416 100755 --- a/plugins/imcloud/Makefile +++ b/plugins/imcloud/Makefile @@ -89,6 +89,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -118,7 +121,7 @@ json_value.o : $(USER_DIR)/json/json_value.cpp json_writer.o : $(USER_DIR)/json/json_writer.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/json/json_writer.cpp $(INCLUDE_PATHS) $(PLUGIN) : json_reader.o json_value.o json_writer.o im_init.o im_logic.o im_mysql.o im_process.o fcgimodule.o util.o star_infos.o logic_unit.o packet_processing.o \ - data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o im_proto.o \ + packet_process_assist.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o im_proto.o \ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lcurl -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/imcloud/im_logic.cc b/plugins/imcloud/im_logic.cc index 9929c05..33056c2 100755 --- a/plugins/imcloud/im_logic.cc +++ b/plugins/imcloud/im_logic.cc @@ -97,7 +97,7 @@ bool Imlogic::OnImMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } switch (packet->operate_code) { diff --git a/plugins/infomation/Makefile b/plugins/infomation/Makefile index f9cf8ff..01b0c01 100755 --- a/plugins/infomation/Makefile +++ b/plugins/infomation/Makefile @@ -84,6 +84,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -113,7 +116,7 @@ json_value.o : $(USER_DIR)/json/json_value.cpp json_writer.o : $(USER_DIR)/json/json_writer.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/json/json_writer.cpp $(INCLUDE_PATHS) $(PLUGIN) : infomation_db.o json_reader.o json_value.o json_writer.o infomation_init.o infomation_logic.o fcgimodule.o util.o star_infos.o logic_unit.o packet_processing.o \ - data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o \ + packet_process_assist.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o \ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/infomation/infomation_logic.cc b/plugins/infomation/infomation_logic.cc index 73992f5..db89864 100755 --- a/plugins/infomation/infomation_logic.cc +++ b/plugins/infomation/infomation_logic.cc @@ -75,7 +75,7 @@ bool Infomationlogic::OnInfomationMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } switch (packet->operate_code) { diff --git a/plugins/market/Makefile b/plugins/market/Makefile index 22c88d0..16c4d33 100755 --- a/plugins/market/Makefile +++ b/plugins/market/Makefile @@ -84,6 +84,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -113,7 +116,7 @@ json_value.o : $(USER_DIR)/json/json_value.cpp json_writer.o : $(USER_DIR)/json/json_writer.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/json/json_writer.cpp $(INCLUDE_PATHS) $(PLUGIN) : market_db.o json_reader.o json_value.o json_writer.o market_init.o market_logic.o fcgimodule.o util.o star_infos.o logic_unit.o packet_processing.o \ - data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o \ + packet_process_assist.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o \ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/market/market_logic.cc b/plugins/market/market_logic.cc index 06fc50f..45fdee2 100755 --- a/plugins/market/market_logic.cc +++ b/plugins/market/market_logic.cc @@ -79,7 +79,7 @@ bool Marketlogic::OnInfomationMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } switch (packet->operate_code) { diff --git a/plugins/netflashsale/Makefile b/plugins/netflashsale/Makefile index 9f768ab..1046830 100755 --- a/plugins/netflashsale/Makefile +++ b/plugins/netflashsale/Makefile @@ -104,6 +104,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -126,7 +129,7 @@ time.o : $(USER_DIR)/logic/time.cc $(USER_DIR)/logic/time.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/time.cc $(INCLUDE_PATHS) $(PLUGIN) : netflash_init.o netflash_logic.o netflash_db.o share_memory.o flash_info.o netflash_kafka.o netflash_schduler_engine.o \ - star_infos.o time.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o time.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CUSTOM_THIRD_PATH)/librdkafka/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient \ $^ -o $@ diff --git a/plugins/netflashsale/netflash_logic.cc b/plugins/netflashsale/netflash_logic.cc index b2aaa0a..b740227 100755 --- a/plugins/netflashsale/netflash_logic.cc +++ b/plugins/netflashsale/netflash_logic.cc @@ -112,6 +112,7 @@ bool Netflashlogic::OnNetflashMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/pay/Makefile b/plugins/pay/Makefile index 4df78b4..a0fa7fd 100644 --- a/plugins/pay/Makefile +++ b/plugins/pay/Makefile @@ -107,6 +107,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -131,7 +134,7 @@ storager_kafka.o : ./storager_kafka.cc ./storager_kafka.h $(PLUGIN) : unionpay_order.o pay_init.o pay_logic.o pay_db.o pay_proto_buf.o schduler_engine.o wx_order.o http_client.o aplipay_clt.o logic_unit.o\ - star_infos.o packet_processing.o data_engine.o data_engine.o data_mysql_engine.o storager_kafka.o \ + star_infos.o packet_process_assist.o packet_processing.o data_engine.o data_engine.o data_mysql_engine.o storager_kafka.o \ data_redis_engine.o mysql_pool.o redis_pool.o \ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a\ $(CUSTOM_THIRD_PATH)/lib/librdkafka.a diff --git a/plugins/pay/pay_logic.cc b/plugins/pay/pay_logic.cc index b366333..c6e8160 100755 --- a/plugins/pay/pay_logic.cc +++ b/plugins/pay/pay_logic.cc @@ -92,7 +92,7 @@ bool Paylogic::OnPayMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/push/push_logic.cc b/plugins/push/push_logic.cc index f2c4fc0..7cb5693 100644 --- a/plugins/push/push_logic.cc +++ b/plugins/push/push_logic.cc @@ -128,7 +128,7 @@ bool CPushlogic::OnPushMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } switch (packet->operate_code) { diff --git a/plugins/quotations/Makefile b/plugins/quotations/Makefile index 5c2c546..9705ca8 100755 --- a/plugins/quotations/Makefile +++ b/plugins/quotations/Makefile @@ -97,6 +97,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -120,7 +123,7 @@ xml_parser.o : $(USER_DIR)/logic/xml_parser.cc $(USER_DIR)/logic/xml_parser.h $(PLUGIN) : quotations_init.o quotations_logic.o schduler_engine.o quotations_proto_buf.o quotations_redis.o quotations_db.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient \ $^ -o $@ diff --git a/plugins/quotations/quotations_logic.cc b/plugins/quotations/quotations_logic.cc index 774d16a..ae8ad1d 100755 --- a/plugins/quotations/quotations_logic.cc +++ b/plugins/quotations/quotations_logic.cc @@ -83,7 +83,7 @@ bool Quotationslogic::OnQuotationsMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/record/Makefile b/plugins/record/Makefile index fe10a5e..eebf823 100644 --- a/plugins/record/Makefile +++ b/plugins/record/Makefile @@ -103,6 +103,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -126,7 +129,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : record_init.o record_logic.o record_db.o record_kafka.o schduler_engine.o record_proto_buf.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CUSTOM_THIRD_PATH)/librdkafka/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/record/record_logic.cc b/plugins/record/record_logic.cc index 0a1bd5a..b940755 100644 --- a/plugins/record/record_logic.cc +++ b/plugins/record/record_logic.cc @@ -86,7 +86,7 @@ bool Recordlogic::OnRecordMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/search/Makefile b/plugins/search/Makefile index c72a1af..c6f986f 100644 --- a/plugins/search/Makefile +++ b/plugins/search/Makefile @@ -97,6 +97,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -120,7 +123,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : search_init.o search_logic.o search_db.o schduler_engine.o search_proto_buf.o fcgimodule.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/search/search_logic.cc b/plugins/search/search_logic.cc index 8c16cdc..7cf0d44 100644 --- a/plugins/search/search_logic.cc +++ b/plugins/search/search_logic.cc @@ -78,7 +78,7 @@ bool Searchlogic::OnSearchMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } switch (packet->operate_code) { diff --git a/plugins/starside/Makefile b/plugins/starside/Makefile index 582ad05..08b6583 100755 --- a/plugins/starside/Makefile +++ b/plugins/starside/Makefile @@ -112,6 +112,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -135,7 +138,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : starside_init.o starside_logic.o schduler_engine.o starside_proto_buf.o starside_db.o starside_info.o fcgimodule.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ $^ -o $@ diff --git a/plugins/starside/starside_logic.cc b/plugins/starside/starside_logic.cc index df42c99..268a894 100755 --- a/plugins/starside/starside_logic.cc +++ b/plugins/starside/starside_logic.cc @@ -98,7 +98,7 @@ bool StarSidelogic::OnStarSideMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } #ifdef _DEBUG diff --git a/plugins/trades/Makefile b/plugins/trades/Makefile index ac2de60..77c7e2b 100755 --- a/plugins/trades/Makefile +++ b/plugins/trades/Makefile @@ -101,6 +101,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -123,7 +126,7 @@ time.o : $(USER_DIR)/logic/time.cc $(USER_DIR)/logic/time.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/time.cc $(INCLUDE_PATHS) $(PLUGIN) : trades_init.o trades_logic.o trades_db.o trades_info.o trades_kafka.o schduler_engine.o trades_proto_buf.o\ - star_infos.o time.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o time.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a $(CUSTOM_THIRD_PATH)/librdkafka/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lpthread -lexpat -lrt -ldl -lmysqlclient \ $^ -o $@ diff --git a/plugins/trades/errno.h b/plugins/trades/errno.h index deb4920..593178b 100755 --- a/plugins/trades/errno.h +++ b/plugins/trades/errno.h @@ -6,7 +6,7 @@ #define STAR_TRADES_ERRNO_H_ enum TRADESERRNO { - FORMAT_ERRNO = -100, +// FORMAT_ERRNO = -100, NO_LOCK_USER_ORDER_VALID = -101, NO_HAVE_TRADES_TIME = -501, NO_HAVE_TRADES_STAR = -502, diff --git a/plugins/trades/operator_code.h b/plugins/trades/operator_code.h index 69b51da..1112993 100755 --- a/plugins/trades/operator_code.h +++ b/plugins/trades/operator_code.h @@ -6,6 +6,7 @@ #include "net/comm_head.h" +#include "comm/comm_head.h" namespace trades_logic { diff --git a/plugins/trades/trades_logic.cc b/plugins/trades/trades_logic.cc index 91202e7..25c191e 100755 --- a/plugins/trades/trades_logic.cc +++ b/plugins/trades/trades_logic.cc @@ -117,6 +117,7 @@ bool Tradeslogic::OnTradesMessage(struct server *srv, const int socket, if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } diff --git a/plugins/users/Makefile b/plugins/users/Makefile index d770e63..8dc73e6 100755 --- a/plugins/users/Makefile +++ b/plugins/users/Makefile @@ -101,6 +101,9 @@ logic_unit.o : $(USER_DIR)/logic/logic_unit.cc $(USER_DIR)/logic/logic_unit.h star_infos.o : $(USER_DIR)/logic/star_infos.cc $(USER_DIR)/logic/star_infos.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/logic/star_infos.cc $(INCLUDE_PATHS) +packet_process_assist.o : $(USER_DIR)/net/packet_process_assist.cc $(USER_DIR)/net/packet_process_assist.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_process_assist.cc $(INCLUDE_PATHS) + packet_processing.o : $(USER_DIR)/net/packet_processing.cc $(USER_DIR)/net/packet_processing.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/net/packet_processing.cc $(INCLUDE_PATHS) @@ -124,7 +127,7 @@ redis_pool.o : $(USER_DIR)/storage/redis_pool.cc $(USER_DIR)/storage/redis_pool $(PLUGIN) : users_init.o users_logic.o users_db.o users_proto_buf.o fcgimodule.o storager_kafka.o\ - star_infos.o logic_unit.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ + star_infos.o logic_unit.o packet_process_assist.o packet_processing.o data_engine.o data_mysql_engine.o data_redis_engine.o mysql_pool.o redis_pool.o\ $(CUSTOM_THIRD_PATH)/dmg_fp/lib/dmg_fp.a $(LIB_DIR)/mylib/base/lib/mybase.a $(LIB_DIR)/mylib/third_party/lib/libhiredis.a \ $(CUSTOM_THIRD_PATH)/lib/librdkafka.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINK_PATHS) -lcurl -lpthread -lexpat -lrt -ldl -lmysqlclient -lfcgi++ \ diff --git a/plugins/users/operator_code.h b/plugins/users/operator_code.h index ce099e9..52d2326 100755 --- a/plugins/users/operator_code.h +++ b/plugins/users/operator_code.h @@ -66,5 +66,8 @@ namespace users_logic { #define R_GET_SERVER_ADDR USERS_TYPE * 1000 + 41 #define S_GET_SERVER_ADDR USERS_TYPE * 1000 + 42 + +#define R_GET_PACKET_KEY USERS_TYPE * 1000 + 43 +#define S_GET_PACKET_KEY USERS_TYPE * 1000 + 44 } #endif diff --git a/plugins/users/users_logic.cc b/plugins/users/users_logic.cc index 9048f36..ec64908 100644 --- a/plugins/users/users_logic.cc +++ b/plugins/users/users_logic.cc @@ -8,6 +8,7 @@ #include "logic/star_infos.h" #include "comm/comm_head.h" #include "net/comm_head.h" +#include "net/packet_process_assist.h" #include "config/config.h" #include "core/common.h" #include "logic/logic_comm.h" @@ -119,7 +120,8 @@ bool Userslogic::OnUsersMessage(struct server *srv, const int socket, return false; if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + //send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); + SEND_UNPACKET_ERROR(socket, ERROR_TYPE, UNPACKET_ERRNO, FORMAT_ERRNO); return false; } @@ -206,6 +208,10 @@ bool Userslogic::OnUsersMessage(struct server *srv, const int socket, OnGetServerAddr(srv, socket, packet); break; } + case R_GET_PACKET_KEY:{ + OnGetPacketCryptKey(srv, socket, packet); + break; + } default: break; } @@ -246,12 +252,18 @@ bool Userslogic::OnBroadcastClose(struct server *srv, const int socket) { bool Userslogic::OnIniTimer(struct server *srv) { if (srv->add_time_task != NULL) { + srv->add_time_task(srv, "users", 30001, 86400, -1); } return true; } bool Userslogic::OnTimeout(struct server *srv, char *id, int opcode, int time) { switch (opcode) { + case 30001: { + unsigned int key = net::CreateKey(); + LOG_DEBUG2("New Key:%d", key); + break; + } default: break; } @@ -1322,4 +1334,28 @@ bool Userslogic::OnGetServerAddr(struct server* srv, int socket, return true; } +bool Userslogic::OnGetPacketCryptKey(struct server* srv, int socket, + struct PacketHead *packet) { + if (packet->packet_length < PACKET_HEAD_LENGTH) { + send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); + return false; + } + + unsigned int key = net::GetKey(); + unsigned int xorRet = 26010 ^ key; + LOG_DEBUG2("packet key[%d], xorRet[%d]", key, xorRet); + + //发送信息 + SEND_UNPACKET_ERROR(socket, USERS_TYPE, (int32) xorRet, packet->session_id); + /*struct PacketControl packet_control_ack; + MAKE_HEAD(packet_control_ack, S_GET_PACKET_KEY, USERS_TYPE, 0, packet->session_id, packet->reserved); + base_logic::DictionaryValue* dic = new base_logic::DictionaryValue(); + dic->SetBigInteger(L"PacketKey", (int64) xorRet ); + packet_control_ack.body_ = dic; + send_message(socket, &packet_control_ack); */ + + return true; +} + + } // namespace users_logic diff --git a/plugins/users/users_logic.cc.orig b/plugins/users/users_logic.cc.orig deleted file mode 100644 index c4b212f..0000000 --- a/plugins/users/users_logic.cc.orig +++ /dev/null @@ -1,1051 +0,0 @@ -// Copyright (c) 2017-2018 The SWP Authors. All rights reserved. -// Created on: 2017年1月12日 Author: kerry - -#include "users/users_logic.h" -#include "users/users_proto_buf.h" -#include "users/operator_code.h" -#include "users/errno.h" -#include "logic/star_infos.h" -#include "comm/comm_head.h" -#include "net/comm_head.h" -#include "config/config.h" -#include "core/common.h" -#include "logic/logic_comm.h" -#include "logic/logic_unit.h" -#include "net/errno.h" -#include -#include -#include "http/http_api.h" - -#define DEFAULT_CONFIG_PATH "./plugins/users/users_config.xml" - -namespace users_logic { - -Userslogic *Userslogic::instance_ = NULL; - -Userslogic::Userslogic() { - if (!Init()) - assert(0); -} - -Userslogic::~Userslogic() { - if (user_db_) { - delete user_db_; - user_db_ = NULL; - } -} - -bool Userslogic::Init() { - bool r = false; - manager_schduler::SchdulerEngine* (*schduler_engine)(void); - std::string path = DEFAULT_CONFIG_PATH; - config::FileConfig *config = config::FileConfig::GetFileConfig(); - if (config == NULL) - return false; - r = config->LoadConfig(path); - - user_db_ = new users_logic::UsersDB(config); - - std::string schduler_library = "./data_share.so"; - std::string schduler_func = "GetManagerSchdulerEngine"; - schduler_engine = (manager_schduler::SchdulerEngine* (*)(void)) - logic::SomeUtils::GetLibraryFunction( - schduler_library, schduler_func); - schduler_engine_ - = (*schduler_engine)(); - if (schduler_engine_ == NULL) - assert(0); - return true; -} - -Userslogic *Userslogic::GetInstance() { - if (instance_ == NULL) - instance_ = new Userslogic(); - return instance_; -} - -void Userslogic::FreeInstance() { - delete instance_; - instance_ = NULL; -} - -bool Userslogic::OnUsersConnect(struct server *srv, const int socket) { - std::string ip; - int port; - logic::SomeUtils::GetIPAddress(socket, ip, port); - LOG_MSG2("ip {%s} prot {%d}", ip.c_str(), port); - - /*测试用户注册 - const std::string testphonenum = "testphonenum"; - const std::string testpasswd = "testpasswd"; - const std::string agentid = "agentid"; - const std::string recommend = "recommend"; - int64 uid = 1; - int64 memid = 1; - int32 type = 0; - int32 result = 1; - bool r = user_db_->RegisterAccount(testphonenum, - testpasswd, type, - uid, result,agentid, - recommend,memid); - if (!r) { //用户已经存在 - LOG_ERROR("user has in sql=================="); - } - */ - /*用户登录token - const std::string phonenum = "phonenumtest"; - const std::string passwd = "passwdtest"; - const std::string ipaddr = "0.0.0.0"; - star_logic::UserInfo userinfo; - bool r = user_db_->LoginAccount(phonenum, passwd, - ipaddr, userinfo); - if (!r || userinfo.uid() == 0) { - LOG_ERROR("user login failed=================="); - } - std::string token; - logic::SomeUtils::CreateToken(userinfo.uid(), passwd, &token); - userinfo.set_token(token); - LOG_ERROR2("=========token===========%s",token.c_str()); - */ - return true; -} - -bool Userslogic::OnUsersMessage(struct server *srv, const int socket, - const void *msg, const int len) { - bool r = false; - struct PacketHead *packet = NULL; - if (srv == NULL || socket < 0 || msg == NULL || len < PACKET_HEAD_LENGTH) - return false; - if (!net::PacketProsess::UnpackStream(msg, len, &packet)) { - LOG_ERROR2("UnpackStream Error socket %d", socket); - send_error(socket, ERROR_TYPE, ERROR_TYPE, FORMAT_ERRNO); - return false; - } - try - { - switch (packet->operate_code) { - case R_ACCOUNT_REGISTER: { - OnRegisterAccount(srv, socket, packet); - break; - } - case R_ACCOUNT_LOGIN: { - OnLoginAccount(srv, socket, packet); - break; - } - case R_RESET_PAY_PASS: { //重置支付密码 - OnResetPayPassWD(srv, socket, packet); - break; - } - - case R_ACCOUNT_ASSET: { - OnUserAccount(srv, socket, packet); - break; - } - case R_ACCOUNT_CHECK: { - OnUserCheckToken(srv, socket, packet); - break; - } - - case R_REGISTER_VERFIY_CODE: { - OnRegisterVerifycode(srv, socket, packet); - break; - } - case R_USRES_RESET_PASSWD: { - OnResetPasswd(srv, socket, packet); - break; - } - case R_WX_LOGIN: { - OnLoginWiXin(srv, socket, packet); - break; - } - case R_WX_BIND_ACCOUNT: { - OnWXBindAccount(srv, socket, packet); - break; - } - case R_ACCOUNT_CHANGEPASSWD: { - OnUserChangePasswd(srv, socket, packet); - break; - } - case R_CERTIFICATION: { - OnCertification(srv, socket, packet); - break; - } - case R_ACCOUNT_REALINFO : - { - OnUserRealInfo(srv, socket, packet); - break; - } - case R_CHECK_ACCOUNT_EXIST : - { - OnCheckAccountExist(srv, socket, packet); - break; - } - case R_USRES_RESET_NICK_NAME : - { - OnResetNickName(srv, socket, packet); - break; - } - - case R_GET_VERSION:{ - OnGetVersion(srv, socket, packet); - break; - } - default: - break; - } -} -catch(...) -{ - LOG_ERROR2("catch : operator[%d]", packet->operate_code); -} - return true; -} - -bool Userslogic::OnUsersClose(struct server *srv, const int socket) { - schduler_engine_->CloseUserInfoSchduler(socket); - return true; -} - -bool Userslogic::OnBroadcastConnect(struct server *srv, const int socket, - const void *msg, const int len) { - return true; -} - -bool Userslogic::OnBroadcastMessage(struct server *srv, const int socket, - const void *msg, const int len) { - printf("OnBroadcastMessage \n"); - return true; -} - -bool Userslogic::OnBroadcastClose(struct server *srv, const int socket) { - return true; -} - -bool Userslogic::OnIniTimer(struct server *srv) { - if (srv->add_time_task != NULL) { - } - return true; -} - -bool Userslogic::OnTimeout(struct server *srv, char *id, int opcode, int time) { - switch (opcode) { - default: - break; - } - return true; -} -bool Userslogic::OnLoginWiXin(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::LoginWiXin login_wixin; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - // bool r = login_wixin.set_http_packet(packet_control->body_); - // if (!r) { - // LOG_DEBUG2("packet_length %d",packet->packet_length); - // send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - // return false; - // } - - std::string ip, passwd = ""; - int port; - logic::SomeUtils::GetIPAddress(socket, ip, port); - star_logic::UserInfo userinfo; - - std::string openid; - std::string deviceid; - packet_control->body_->GetString(L"openid",&openid); - packet_control->body_->GetString(L"deviceId",&deviceid); - - LOG_ERROR2("get request value openid : %s,deviceid: %s",openid.c_str(),deviceid.c_str()); - base_logic::DictionaryValue ret_list; - bool r = user_db_->LoginWiXin(openid, deviceid,ip, ret_list); - if (!r) { - send_error(socket, ERROR_TYPE, NO_PASSWORD_ERRNOR, packet->session_id); - return false; - } - - //userinfo.set_token(token); - //发送用信息 - //SendUserInfo(socket, packet->session_id, S_WX_LOGIN, userinfo); - - struct PacketControl packet_reply; - //base_logic::DictionaryValue ret_list; - MAKE_HEAD(packet_reply, S_WX_LOGIN, INFO_TYPE, 0,packet->session_id, 0); - base_logic::FundamentalValue* result = new base_logic::FundamentalValue(1); - //token 计算 - std::string token; - logic::SomeUtils::CreateToken(userinfo.uid(), passwd, &token); - int64 ret = 1; - ret_list.SetBigInteger(L"result",ret); - ret_list.SetString(L"token",token); - - packet_reply.body_ = &ret_list; - send_message(socket,&packet_reply); - return true; -} -bool Userslogic::OnWXBindAccount(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::WXBindAccount wx_bind_account; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = wx_bind_account.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - int64 uid = 0; - int32 result = 0; - //注册数据库 - // - - r = user_db_->WXBindAccount(wx_bind_account.phone_num(), - wx_bind_account.passwd(), 0, uid, result, - wx_bind_account.openid(), - wx_bind_account.nick_name(), - wx_bind_account.head_url(), - wx_bind_account.agentid(), - wx_bind_account.recommend(), - wx_bind_account.device_id(), - wx_bind_account.member_id()); - // - if (!r || result == 0) { //用户已经存在 - send_error(socket, ERROR_TYPE, NO_USER_EXIST, packet->session_id); - return false; - } - - //返回绑定信息 - users_logic::net_reply::RegisterAccount net_register_account; - net_register_account.set_result(1); - net_register_account.set_uid(uid); - - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_ACCOUNT_REGISTER, 1, 0, packet->session_id, - 0); - net_packet_control.body_ = net_register_account.get(); - send_message(socket, &net_packet_control); - return true; -} - -bool Userslogic::OnUserChangePasswd(struct server* srv, int socket, - struct PacketHead *packet) { - - bool r = false; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - - std::string phone_num; - std::string old_passwd; - std::string new_passwd; - bool r1 = packet_control->body_->GetString(L"phone",&phone_num); - bool r2 = packet_control->body_->GetString(L"oldpasswd",&old_passwd); - bool r3 = packet_control->body_->GetString(L"newpasswd",&new_passwd); - r = r1 && r2 && r3; - if(!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - r = user_db_->UserChangePasswd(phone_num,old_passwd,new_passwd); - - if (!r) { - send_error(socket, ERROR_TYPE, NO_USER_EXIST, packet->session_id); - return false; - } - - base_logic::DictionaryValue* ret = new base_logic::DictionaryValue(); - base_logic::FundamentalValue* result = new base_logic::FundamentalValue(1); - ret->Set(L"result", result); - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_ACCOUNT_REGISTER, 1, 0, packet->session_id, - 0); - net_packet_control.body_ = ret; - send_message(socket, &net_packet_control); - return true; - -} - - -bool Userslogic::OnRegisterAccount(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::RegisterAccount register_account; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - // bool r = register_account.set_http_packet(packet_control->body_); - // if (!r) { - // LOG_DEBUG2("packet_length %d",packet->packet_length); - // send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - // return false; - // } - - std::string passwd; - std::string phonenum; - std::string agentId; - int64 memberId; - std::string recommend; - bool r1 = packet_control->body_->GetString(L"pwd", &passwd); - bool r2 = packet_control->body_->GetString(L"phone", &phonenum); - bool r3 = packet_control->body_->GetString(L"agentId", &agentId); - bool r4 = packet_control->body_->GetString(L"recommend", &recommend); - bool r5 = packet_control->body_->GetBigInteger(L"memberId", &memberId); - LOG_ERROR2("---------------------%d,%d,%d,%d,%d",r1,r2,r3,r4,r5); - bool r = (r1 && r2 && r3 && r4 && r5); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - int64 uid = 1; - int32 result = 0; - - //注册数据库 - r = user_db_->RegisterAccount(phonenum, - passwd, 0, - uid, result,agentId, - recommend,memberId); - if (!r) { //用户已经存在 - send_error(socket, ERROR_TYPE, NO_USER_EXIST, packet->session_id); - return false; - } - - //返回注册信息 - users_logic::net_reply::RegisterAccount net_register_account; - net_register_account.set_result(1); - net_register_account.set_uid(uid); - - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_ACCOUNT_REGISTER, 1, 0, packet->session_id, - 0); - net_packet_control.body_ = net_register_account.get(); - send_message(socket, &net_packet_control); - return true; -} - -bool Userslogic::OnUserAccount(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::UserAccount user_account; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = user_account.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - //数据库获取用户余额 - double balance = 0.0; - star_logic::UserInfo userinfo; - users_logic::net_reply::Balance net_balance; - r = schduler_engine_->GetUserInfoSchduler(user_account.uid(), &userinfo); - if (!r){ - LOG_DEBUG2("uid[%ld]",user_account.uid()); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return r; - } - - std::string pwd; - r = user_db_->AccountBalance(user_account.uid(), balance, pwd); - if (!r){ - LOG_DEBUG2("uid[%ld]",user_account.uid()); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return r; - } - userinfo.set_balance(balance); - - net_balance.set_nick_name(userinfo.nickname()); - std::string t_sUserHeadUrl = userinfo.head_url(); - net_balance.set_head_url(t_sUserHeadUrl); - net_balance.set_balance(userinfo.balance()); - net_balance.set_total_amt(0.0); - net_balance.set_market_cap(0.0); - if (pwd.length() > 0) - net_balance.set_is_setpwd(0); - else - net_balance.set_is_setpwd(1); - - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_ACCOUNT_ASSET, USERS_TYPE, 0, - packet->session_id, 0); - net_packet_control.body_ = net_balance.get(); - send_message(socket, &net_packet_control); - - return true; -} - -bool Userslogic::OnUserRealInfo(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::UserRealInfo user_real_info; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = user_real_info.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - // - //double balance = 0.0; - star_logic::UserInfo userinfo; - users_logic::net_reply::RealInfo net_real_info; - //获取用户信息 - r = schduler_engine_->GetUserInfoSchduler(user_real_info.uid(), &userinfo); - if (!r) { - LOG_DEBUG2("uid[%ld]",user_real_info.uid()); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - if (userinfo.id_card().length() < 10) //如果没有实名认证信息则获取 - { - std::string r_name = "" , id_card = ""; - r = user_db_->AccountRealNameInfo(user_real_info.uid(), r_name, id_card); - if (r_name != "") - { - userinfo.set_realname(r_name); - userinfo.set_id_card(id_card); - } - LOG_DEBUG2("realname[%s], id_card[%s], realname2[%s], id_card2[%s], ", - r_name.c_str(), id_card.c_str(), userinfo.realname().c_str(), userinfo.id_card().c_str()); - } - //} -// net_real_info.set_balance(userinfo.balance()); - net_real_info.set_realname(userinfo.realname()); - net_real_info.set_id_card(userinfo.id_card()); - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_ACCOUNT_REALINFO, USERS_TYPE, 0, - packet->session_id, 0); - net_packet_control.body_ = net_real_info.get(); - send_message(socket, &net_packet_control); - - return true; -} - -bool Userslogic::OnLoginAccount(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::LoginAccount login_account; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = login_account.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - std::string ip; - int port; - logic::SomeUtils::GetIPAddress(socket, ip, port); - - star_logic::UserInfo userinfo; - r = user_db_->LoginAccount(login_account.phone_num(), login_account.passwd(), - ip, userinfo); - if (!r) { - send_error(socket, ERROR_TYPE, NO_PASSWORD_ERRNOR, packet->session_id); - return false; - } - - //token 计算 - std::string token; - logic::SomeUtils::CreateToken(userinfo.uid(), login_account.passwd(), &token); - userinfo.set_token(token); - userinfo.set_phone_num(login_account.phone_num()); - - //发送用信息 - SendUserInfo(socket, packet->session_id, S_ACCOUNT_LOGIN, userinfo); - return true; -} - -bool Userslogic::OnUserCheckToken(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::CheckToken check_token; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = check_token.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - star_logic::UserInfo userinfo; - std::string ip; - int port; - logic::SomeUtils::GetIPAddress(socket, ip, port); - userinfo.set_token(check_token.token()); - //check token - r = logic::SomeUtils::VerifyToken(check_token.uid(), check_token.token()); - if (!r) { - LOG_DEBUG2("uid[%ld]",check_token.uid()); - send_error(socket, ERROR_TYPE, NO_CHECK_TOKEN_ERRNO, packet->session_id); - return false; - } - - //获取用户信息 - r = user_db_->GetUserInfo(check_token.uid(), ip, userinfo); - if(!r){ - LOG_DEBUG2("uid[%ld],ip[%s]",check_token.uid(), ip.c_str()); - send_error(socket, ERROR_TYPE, NO_CHECK_TOKEN_ERRNO, packet->session_id); - return false; - } - - //发送用信息 - SendUserInfo(socket, packet->session_id, S_ACCOUNT_CHECK, userinfo); - return true; -} -bool Userslogic::OnResetPasswd(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::RegisterAccount register_account; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - - std::string phonenum; - std::string passwd; - bool r1 = packet_control->body_->GetString(L"pwd", &passwd); - bool r2 = packet_control->body_->GetString(L"phone", &phonenum); - - bool r = (r1 && r2); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - int64 uid = 1; - int32 result = 0; - r = user_db_->ResetAccount(phonenum,passwd); - if (!r) { - LOG_DEBUG2("phonenum[%s],passwd[%s]",phonenum.c_str(),passwd.c_str()); - send_error(socket, ERROR_TYPE, NO_USER_EXIST, packet->session_id); - return false; - } - - struct PacketControl packet_reply; - MAKE_HEAD(packet_reply, S_USRES_RESET_PASSWD, USERS_TYPE, 0,packet->session_id, 0); - base_logic::DictionaryValue ret; - base_logic::FundamentalValue* m_result = new base_logic::FundamentalValue(1); - ret.Set(L"result",m_result); - packet_reply.body_ = &ret; - send_message(socket,&packet_reply); - return r; -} -void executeCMD(const char *cmd, char *result) { - char buf_ps[1024]; - char ps[1024]= {0}; - FILE *ptr; - strcpy(ps, cmd); - if((ptr=popen(ps, "r"))!=NULL) - { - while(fgets(buf_ps, 1024, ptr)!=NULL) - { - strcat(result, buf_ps); - if(strlen(result)>1024) - break; - } - pclose(ptr); - ptr = NULL; - } - else - { - printf("popen %s error\n", ps); - } -} -bool Userslogic::OnRegisterVerifycode(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::RegisterVerfiycode register_vercode; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = register_vercode.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - std::string phone = register_vercode.phone().c_str(); - -/* - ////检测号码是否已经注册 - if(check_account_flag == CHECK_ACCOUNT_Y){ - r =user_db_->CheckAccountExist(phone); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, NO_USER_EXIST_REGISTER, packet->session_id); - return true; - } - } -*/ - - int64 rand_code = 100000 + rand() % (999999 - 100000 + 1); - std::string shell_sms = SHELL_SMS; - std::stringstream ss; - ss << SHELL_SMS << " " << phone << " " - <session_id); - return false; - } - - //发送信息 - int64 code_time = time(NULL); - std::string v_token = SMS_KEY + base::BasicUtil::StringUtil::Int64ToString(code_time) + - base::BasicUtil::StringUtil::Int64ToString(rand_code) + phone; - base::MD5Sum md5(v_token.c_str()); - std::string token = md5.GetHash(); - LOG_MSG2("====v_token = %s",v_token.c_str()); - users_logic::net_reply::RegisterVerfiycode register_verfiy; - register_verfiy.set_code_time(code_time); - register_verfiy.set_token(token); - int64 result_ = 1; - register_verfiy.set_result(result_); - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control,S_REGISTER_VERFIY_CODE, 1, 0, packet->session_id, 0); - net_packet_control.body_ = register_verfiy.get(); - send_message(socket, &net_packet_control); - - return true; -} - -bool Userslogic::SendUserInfo(const int socket, const int64 session, - const int32 opcode, - star_logic::UserInfo& userinfo) { - userinfo.set_socket_fd(socket); - userinfo.set_is_effective(true); - - //写入共享数据库中 - users_logic::net_reply::LoginAccount net_login_account; - users_logic::net_reply::UserInfo net_userinfo; - net_userinfo.set_balance(userinfo.balance()); - net_userinfo.set_phone(userinfo.phone_num()); - net_userinfo.set_uid(userinfo.uid()); - net_userinfo.set_type(userinfo.type()); - net_userinfo.set_agent_name(userinfo.nickname()); - net_userinfo.set_avatar_large(userinfo.head_url()); - net_login_account.set_userinfo(net_userinfo.get()); - net_login_account.set_token(userinfo.token()); - schduler_engine_->SetUserInfoSchduler(userinfo.uid(), &userinfo); - - star_logic::UserInfo tuserinfo; - schduler_engine_->GetUserInfoSchduler(userinfo.uid(), &tuserinfo); - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, opcode, 1, 0, session, 0); - net_packet_control.body_ = net_login_account.get(); - send_message(socket, &net_packet_control); - return true; -} - -bool Userslogic::OnResetPayPassWD(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::ModifyPwd modifypwd; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = modifypwd.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - std::string phone = modifypwd.phone(); - std::string v_token = SMS_KEY + base::BasicUtil::StringUtil::Int64ToString(modifypwd.timestamp()) + - modifypwd.vcode().c_str() + phone; - base::MD5Sum md5(v_token.c_str()); - std::string token = md5.GetHash(); - - users_logic::net_reply::ModifyPwd net_modifypwd; - int status = 1; //0 sucess ,1 failed - LOG_DEBUG2("v_token[%s]token[%s]vtoken[%s]", v_token.c_str(), token.c_str(),modifypwd.vtoken().c_str()); - LOG_DEBUG2("type [%d]", modifypwd.type()); - if (!strcmp(token.c_str(), modifypwd.vtoken().c_str()) - || modifypwd.type() == 0) //验证token type 0-设置密码1-重置密码 - { - LOG_DEBUG2("phone[%s]token[%s]vtoken[%s]___________________", modifypwd.phone().c_str(), token.c_str(),modifypwd.vtoken().c_str()); - LOG_DEBUG2("pwd[%s]___________________", modifypwd.pwd().c_str()); - //std::string phone = modifypwd.phone() ; - std::string pwd = modifypwd.pwd() ; - r = user_db_->ModifyPwd(modifypwd.uid(), pwd); - LOG_DEBUG2("pwd[%s]",pwd.c_str()); - if (r) status = 0; - } - net_modifypwd.set_status(status); - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_RESET_PAY_PASS, USERS_TYPE, 0, - packet->session_id, 0); - net_packet_control.body_ = net_modifypwd.get(); - send_message(socket, &net_packet_control); - - return true; -} - -bool Userslogic::OnCertification(struct server* srv, int socket, - struct PacketHead *packet) { - - users_logic::net_request::Certification cerfic; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_= (struct PacketControl*) (packet); - bool r = cerfic.set_http_packet(packet_->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - std::string idcard = cerfic.id_card();//"411325199005217439"; - std::string name = cerfic.realname();//"唐伟"; - - //std::string idcard = "411325199005217439"; - //std::string name = "唐伟"; - //阿里云接口 - std::string strUrl = "http://idcardreturnphoto.haoservice.com/idcard/VerifyIdcardReturnPhoto"; - ////阿里云接口code - //std::string strHeader = "Authorization:APPCODE 900036feeee64ae089177dd06b25faa9"; - std::string strHeader = "Authorization:APPCODE e361298186714a6faea52316ff1d5c32"; - std::string strResult; - base_logic::DictionaryValue dic; - dic.SetString(L"cardNo", idcard); - dic.SetString(L"realName", name); -// base_http::HttpAPI::RequestGetMethod(strUrl, &dic, strResult, strHeader, 1); - base_http::HttpAPI::RequestGetMethod(strUrl, &dic, strResult, 1); - LOG_DEBUG2("strResult [%s]___________________________________________________", strResult.c_str()); - - users_logic::net_reply::TResult r_ret;; - r_ret.set_result(1); - //r_ret.set_result(0); -//_________________________________________________________ - base_logic::ValueSerializer* serializer = base_logic::ValueSerializer::Create( - base_logic::IMPL_JSON, &strResult, false); - std::string err_str; - DicValue* dicResultJosn; - int32 err = 0; - DicValue* dicJosn = (DicValue*)serializer->Deserialize(&err, &err_str); - r = false; - if (dicJosn != NULL) { - r = dicJosn->GetDictionary(L"result", &dicResultJosn); - if (r) - { - //解析第二层 - int32 err = 0; - bool bResultIsOk = false; - if (dicResultJosn != NULL) { - r = dicResultJosn->GetBoolean(L"isok", &bResultIsOk); - if (r) - { - //更新数据 - std::stringstream strsql; - if (bResultIsOk) - { - LOG_DEBUG("strResult ___________________________________________________ok" ); - //mysql_engine_->WriteData(strsql.str()); - //map_IdCard_Info_.erase(l_it); - r = user_db_->Certification(cerfic.uid(), cerfic.id_card(), cerfic.realname()); - if (r) - r_ret.set_result(0); - } - else - LOG_DEBUG("strResult ___________________________________________________ err" ); - } - } - } - } - else { - LOG_DEBUG("josn Deserialize error[]___________________________________________________ err" ); - } -//_____________________________________________________________________________________________ - -// - if(!r){ - //code 3 curl_easy_perform failed: HTTP response code said error - //网站报错, 特殊处理 - r_ret.set_result(0); - r = user_db_->Certification(cerfic.uid(), cerfic.id_card(), cerfic.realname()); - } - - struct PacketControl packet_control; - MAKE_HEAD(packet_control, S_CERTIFICATION, USERS_TYPE, 0, packet->session_id, 0); - packet_control.body_ = r_ret.get(); - send_message(socket, &packet_control); -/* -*/ - return true; -} - -bool Userslogic::OnCheckAccountExist(struct server* srv, int socket, - struct PacketHead *packet) { - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - users_logic::net_request::CheckAccountExistReq check_acount_exist_req; - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = check_acount_exist_req.set_http_packet(packet_control->body_); - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - std::string phone = check_acount_exist_req.phone().c_str(); - int32 existFlag = 0; - //检测号码是否已经注册 - r =user_db_->CheckAccountExist(phone, existFlag); - if(!r){ - LOG_DEBUG2("phone[%s]",phone.c_str()); - send_error(socket, ERROR_TYPE, NO_DATABASE_ERR, packet->session_id); - return false; - } - - //发送信息 - struct PacketControl packet_control_ack; - MAKE_HEAD(packet_control_ack,S_CHECK_ACCOUNT_EXIST, 1, 0, packet->session_id, 0); - base_logic::DictionaryValue dic; - dic.SetInteger(L"result", existFlag); /*0表示不存在未注册*/ - packet_control_ack.body_ = &dic; - send_message(socket, &packet_control_ack); - - return true; -} - -bool Userslogic::OnResetNickName(struct server* srv, int socket, - struct PacketHead *packet) { - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - - bool r1,r2,r3; - int64 uid; - std::string token; - std::string nickname; - r1 = packet_control->body_->GetBigInteger(L"uid", &uid); - r2 = packet_control->body_->GetString(L"token", &token); - r3 = packet_control->body_->GetString(L"nickname", &nickname); - - bool r = (r1 && r2 && r3); - if (!r1 || !r2 || !r3) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - - //check token - r = logic::SomeUtils::VerifyToken(uid, token); - if (!r) { - LOG_DEBUG2("uid[%ld], token[%s]",uid, token.c_str()); - send_error(socket, ERROR_TYPE, NO_CHECK_TOKEN_ERRNO, packet->session_id); - return false; - } - - int32 flag = 0; - r = user_db_->ModifyNickName(uid,nickname,flag); - if (!r) { - LOG_DEBUG2("uid[%ld], nickname[%s]",uid, nickname.c_str()); - send_error(socket, ERROR_TYPE, NO_DATABASE_ERR, packet->session_id); - return false; - } - - //发送信息 - struct PacketControl packet_control_ack; - MAKE_HEAD(packet_control_ack,S_USRES_RESET_NICK_NAME, 1, 0, packet->session_id, 0); - base_logic::DictionaryValue dic; - dic.SetInteger(L"result", 0); - if (r) { - //获取用户信息 - star_logic::UserInfo userinfo; - r = user_db_->GetUserInfo(uid, "", userinfo); - if(!r){ - LOG_DEBUG2("GetUserInfo error, uid[%ld]",uid); - } - else{ - userinfo.set_socket_fd(socket); - userinfo.set_is_effective(true); - schduler_engine_->SetUserInfoSchduler(userinfo.uid(), &userinfo); - dic.SetInteger(L"result", 1); - } - } - packet_control_ack.body_ = &dic; - send_message(socket, &packet_control_ack); - - return true; -} -bool Userslogic::OnGetVersion(struct server* srv, int socket, - struct PacketHead *packet) { - users_logic::net_request::TGetVersion get_version; - if (packet->packet_length <= PACKET_HEAD_LENGTH) { - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } - struct PacketControl* packet_control = (struct PacketControl*) (packet); - bool r = get_version.set_http_packet(packet_control->body_); - - if (!r) { - LOG_DEBUG2("packet_length %d",packet->packet_length); - send_error(socket, ERROR_TYPE, FORMAT_ERRNO, packet->session_id); - return false; - } -/* - std::string ip; - int port; - logic::SomeUtils::GetIPAddress(socket, ip, port); - - swp_logic::UserInfo userinfo; -*/ - users_logic::net_reply::TGetVersion net_get_version; - r = user_db_->GetVersion(get_version.type(), net_get_version); - if (!r) { - send_error(socket, ERROR_TYPE, NO_VERSION_INFO, packet->session_id); - return false; - } - - struct PacketControl net_packet_control; - MAKE_HEAD(net_packet_control, S_GET_VERSION, 1, 0, packet->session_id, 0); - net_packet_control.body_ = net_get_version.get(); - send_message(socket, &net_packet_control); - - return true; -} -} // namespace trades_logic diff --git a/plugins/users/users_logic.h b/plugins/users/users_logic.h index 3a0af64..50e37c0 100755 --- a/plugins/users/users_logic.h +++ b/plugins/users/users_logic.h @@ -94,6 +94,8 @@ class Userslogic { bool OnGetServerAddr(struct server* srv, int socket, struct PacketHead *packet); + bool OnGetPacketCryptKey(struct server* srv, int socket, struct PacketHead *packet); + private: bool Init(); private: diff --git a/pub/comm/comm_head.h b/pub/comm/comm_head.h index eb99d2c..ed9e2ae 100755 --- a/pub/comm/comm_head.h +++ b/pub/comm/comm_head.h @@ -13,7 +13,8 @@ enum TIME_TASK { }; enum PUBLIC_ERRNO { - FORMAT_ERRNO = -100 + FORMAT_ERRNO = -100, + UNPACKET_ERRNO = -117 }; enum PACKET_ERROR { diff --git a/pub/logic/logic_unit.cc b/pub/logic/logic_unit.cc index cb76a99..7c68eac 100755 --- a/pub/logic/logic_unit.cc +++ b/pub/logic/logic_unit.cc @@ -353,7 +353,7 @@ bool SendUtils::SendBytes(int socket, const void* bytes, int32 len, } bool SendUtils::SendMessage(int socket, struct PacketHead* packet, - const char* file, int32 line) { + const char* file, int32 line, int16 flag) { bool r; void *packet_stream = NULL; int32_t packet_stream_length = 0; @@ -362,11 +362,16 @@ bool SendUtils::SendMessage(int socket, struct PacketHead* packet, if (socket <= 0 || packet == NULL) return false; - if (net::PacketProsess::PacketStream(packet, &packet_stream, + if (1 == flag && net::PacketProsess::PacketStream(packet, &packet_stream, &packet_stream_length) == false) { LOG_ERROR2("Call PackStream failed in %s:%d", file, line); r = false; goto MEMFREE; + } else if (0 == flag && net::PacketProsess::PacketClearStream(packet, &packet_stream, + &packet_stream_length) == false) { + LOG_ERROR2("Call PacketClearStream failed in %s:%d", file, line); + r = false; + goto MEMFREE; } ret = SendFull(socket, reinterpret_cast(packet_stream), diff --git a/pub/logic/logic_unit.h b/pub/logic/logic_unit.h index 93ae217..9232420 100755 --- a/pub/logic/logic_unit.h +++ b/pub/logic/logic_unit.h @@ -33,7 +33,7 @@ class SendUtils { bool SendBytes(int socket, const void* bytes, int32 len, const char* file, int32 line); bool SendMessage(int socket, struct PacketHead* packet, const char* file, - int32 line); + int32 line, int16 flag = 1); private: struct threadrw_t* socket_lock_; }; @@ -171,7 +171,7 @@ extern std::map error_code_msgs; } #define send_message(socket, packet) \ - logic::SendUtils::GetInstance()->SendMessage(socket, packet, __FILE__, __LINE__)\ + logic::SendUtils::GetInstance()->SendMessage(socket, packet, __FILE__, __LINE__, 1)\ #define send_full(socket, buffer, len) \ logic::SendUtils::GetInstance()->SendFull(socket, buffer, len)\ @@ -186,6 +186,16 @@ extern std::map error_code_msgs; send_message(socket, &packet_control); \ } while(0) +#define SEND_UNPACKET_ERROR(socket, type, error_code, session) \ + do { \ + struct PacketControl packet_control; \ + MAKE_HEAD(packet_control, ERROR_TYPE, type, 0, session, 0); \ + base_logic::DictionaryValue dic; \ + dic.SetInteger(L"result", error_code); \ + packet_control.body_ = &dic; \ + logic::SendUtils::GetInstance()->SendMessage(socket, &packet_control, __FILE__, __LINE__, 0); \ + } while(0) + #define closelockconnect(socket) \ shutdown(socket, SHUT_RDWR); #endif /* LOGIC_UNIT_H_ */ diff --git a/pub/net/packet_process_assist.cc b/pub/net/packet_process_assist.cc new file mode 100644 index 0000000..5eaf748 --- /dev/null +++ b/pub/net/packet_process_assist.cc @@ -0,0 +1,399 @@ +// Copyright (c) 2016-2017 The KID Authors. All rights reserved. +// Created on: 2016年12月30日 Author: kerry + +#include "net/packet_process_assist.h" + + +namespace net { + +bool checksum(const char* src_data, uint16& check_ret) { + bool ret = true; + + do { + const int16_t* opt_data = reinterpret_cast(src_data); + if (opt_data == NULL || src_data == NULL) { + ret = false; + /*TODO*/ + // warn_log(); + break; + } + int32_t accu_sum = 0; + int32_t data_len = strlen(src_data); + + while (data_len > 1) { + accu_sum += *(opt_data); + opt_data++; + data_len = data_len - 2; + + if (accu_sum & 0x80000000) { + accu_sum = (accu_sum >> 16) + (accu_sum & 0xFFFF); + } + } + + if (data_len == 1) { + accu_sum += *(reinterpret_cast(opt_data)); + } + + while (accu_sum >> 16) { + accu_sum = (accu_sum >> 16) + (accu_sum & 0xFFFF); + } + + //check_ret = (accu_sum == 0xFFFF)?~accu_sum:accu_sum; + check_ret = 0xFFFF & accu_sum; + }while(0); + + return ret; +} + +//加密 key +unsigned int key[5] = {1,2,3,4,5}; // NOLINT //key +unsigned int GetKey() { + return key[0]*10000+key[1]*1000+key[2]*100+key[3]*10+0; +} + +void SetKey(unsigned int k) { + key[0] = k/10000; + key[1] = (k%10000)/1000; + key[2] = (k%1000)/100; + key[3] = (k%100)/10; +} + +unsigned int CreateKey() { + unsigned int randKey = 0 + rand() % (99999 - 0 + 1); + key[0] = randKey/10000; + key[1] = (randKey%10000)/1000; + key[2] = (randKey%1000)/100; + key[3] = (randKey%100)/10; + return key[0]*10000+key[1]*1000+key[2]*100+key[3]*10+0; +} + + +// jiami +void encrypt(unsigned int *v1, unsigned int *v2, unsigned int *k, int rounds) { + unsigned int y = *v1, z = *v2, sum = 0, i = 0; + unsigned int delta = 0x9e3779b9; + int a = k[0], b = k[1], c = k[2], d = k[3]; + for (i=0; i < rounds; i++) { + sum += delta; + y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); + z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); + } + *v1 = y; + *v2 = z; +} + +// jiemi +void decrypt(unsigned int *v1, unsigned int *v2, unsigned int *k, int rounds) { + unsigned int y = *v1, z = *v2, i = 0, sum; + if (rounds == 32) + sum = 0xc6ef3720; + else + sum = 0xe3779b90; + // sum = 0x9e3779b9; + unsigned int delta = 0x9e3779b9; + int a = k[0], b = k[1], c = k[2], d = k[3]; + for (i = 0; i < rounds; i++) { + z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); + y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); + sum -= delta; + } + *v1 = y; + *v2 = z; +} + +// 16 or 32 rounds jiami +char* str_en_8byte(char *clearmsg, int len, int rounds, int& len1) { + //int len = strlen(clearmsg); + //int n = len/8; + //int len1 = (n+1)*8;//传入的大小已经补全8 的倍数 + len1 = len; + int i; + char *en = (char*)malloc(len1*sizeof(char) + 1); // NOLINT + //memcpy(en, clearmsg, strlen(clearmsg)); + memcpy(en, clearmsg, len); + //for (i = len; i < len1; ++i) + // *(en+i) = '\0'; + unsigned int *y1, *y2; + for (i = 0; i < len1; i += 8) { + y1 = (unsigned int *)&en[i]; // NOLINT + y2 = (unsigned int *)&en[i+4]; // NOLINT + encrypt(y1, y2, key, rounds); + } + en[len1] = '\0'; + return en; +} + + +// 16 or 32 rounds jiemi +char* str_de_8byte(char *encryptedmsg, int len, int rounds) { + int i; + //int len = strlen(encryptedmsg); + char *de = (char*)malloc(len*sizeof(char) + 1); // NOLINT + //memcpy(de, encryptedmsg, sizeof(encryptedmsg)); + memcpy(de, encryptedmsg, len); + unsigned int *y1, *y2; + for (i = 0; i < len; i += 8) { + y1 = (unsigned int *)&de[i]; // NOLINT + y2 = (unsigned int *)&de[i+4]; // NOLINT + decrypt(y1, y2, key, rounds); + } + *(de+len) = '\0'; + return de; +} + +std::string str_en(std::string a, int rounds) { + char destCh[100]; + memset(destCh, '\0', sizeof(destCh)); + int start = 0, end = 0, num = 0, i; + std::string temp[100]; + for (i=0; i a.length()) { + temp[num] = a.substr(i, a.length()-i+1); + num++; + } else { + temp[num] = a.substr(i, 8); + num++; + } + } + int j, len; + char* tempCh = NULL; + for (j=0; j strEn.length()) { + tempDe[num] = strEn.substr(i, strEn.length()-i+1); + num++; + } else { + tempDe[num] = strEn.substr(i, 8); + num++; + } + } + for (j=0; jzalloc = (alloc_func)0; + zlibStream_->zfree = (free_func)0; + zlibStream_->opaque = (voidpf)0; + + // Initialise the z_stream + err = deflateInit(zlibStream_,9);//9:Z_BEST_COMPRESSION + if (err != Z_OK) { + return err; + } + ulTotalZipLen_ = 0; + } + // Use whatever input is provided + zlibStream_->next_in = const_cast(pUnZipData); + zlibStream_->avail_in = ulUnZipLen; + zlibStream_->next_out = pZipData; + zlibStream_->avail_out = ulZipLen; + // Try to unzip the data + err = deflate(zlibStream_, Z_SYNC_FLUSH); + if ((err == Z_OK) && (zlibStream_->avail_in == 0)) { + // All available input has been processed, everything ok. + // Set the size to the amount unzipped in this call (including all recursive calls) + ulZipLen = (zlibStream_->total_out - ulTotalZipLen_); + ulTotalZipLen_ = zlibStream_->total_out; + } + + if (err != Z_OK) + ulZipLen = 0; + return err; +} + +void MZip::EnableCompress(bool bEnable) { + bCompress_ = bEnable; +} + + + +#define MAX_BLOCKSIZE 184320 + +MUnZip::MUnZip(void) + : zlibStream_(NULL) + , unZipLen_(0) +{ +} + +MUnZip::~MUnZip(void) +{ + if(zlibStream_) { + inflateEnd(zlibStream_); + delete zlibStream_; + zlibStream_ = NULL; + } +} + +unsigned long MUnZip::UnZipData(const unsigned char* pZipData, unsigned long ulZipLen, + unsigned char** ppUnZipData) { + if(pZipData == NULL || ulZipLen == 0) { + return 0; + } + unsigned long ulUnZipLen = 0; + unsigned char ucType = *(unsigned char*)pZipData; + + ulUnZipLen = ulZipLen * 2; + if(ulUnZipLen > MAX_BLOCKSIZE + 300) { + ulUnZipLen = MAX_BLOCKSIZE + 300; + } + *ppUnZipData = new unsigned char[ulUnZipLen]; + if(*ppUnZipData) { + int Ret = UnZip(pZipData,ulZipLen,ppUnZipData,&ulUnZipLen); + if(Ret != Z_OK || ulUnZipLen == 0) { + delete []*ppUnZipData; + *ppUnZipData = NULL; + ulUnZipLen = 0; + } + } + return ulUnZipLen; +} + +int MUnZip::UnZip(const unsigned char* pZipData, unsigned long ulZipLen, + unsigned char** ppUnZipData, unsigned long* ulUnZipLen, int iRecursion) { + int err = Z_DATA_ERROR; + if (zlibStream_ == NULL) { + zlibStream_ = new z_stream; + // Initialise stream values + zlibStream_->zalloc = (alloc_func)0; + zlibStream_->zfree = (free_func)0; + zlibStream_->opaque = (voidpf)0; + + // Set output data streams, do this here to avoid overwriting on recursive calls + zlibStream_->next_out = (*ppUnZipData); + zlibStream_->avail_out = (*ulUnZipLen); + + // Initialise the z_stream + err = inflateInit(zlibStream_); + if (err != Z_OK) + { + return err; + } + unZipLen_ = 0; + } + // Use whatever input is provided + zlibStream_->next_in = const_cast(pZipData); + zlibStream_->avail_in = ulZipLen; + + // Only set the output if not being called recursively + if (iRecursion == 0) { + zlibStream_->next_out = (*ppUnZipData); + zlibStream_->avail_out = (*ulUnZipLen); + } + + // Try to unzip the data + err = inflate(zlibStream_, Z_SYNC_FLUSH); + if ((err == Z_OK) && (zlibStream_->avail_out == 0) && (zlibStream_->avail_in != 0)) { + // Output array was not big enough, call recursively until there is enough space + // What size should we try next + unsigned long newLength = (*ulUnZipLen) *= 2; + if (newLength == 0) + newLength = ulZipLen * 2; + + // Copy any data that was successfully unzipped to new array + BYTE *temp = new BYTE[newLength]; + memcpy(temp, (*ppUnZipData), (zlibStream_->total_out - unZipLen_)); + delete[] (*ppUnZipData); + (*ppUnZipData) = temp; + (*ulUnZipLen) = newLength; + + // Position stream output to correct place in new array + zlibStream_->next_out = (*ppUnZipData) + (zlibStream_->total_out - unZipLen_); + zlibStream_->avail_out = (*ulUnZipLen) - (zlibStream_->total_out - unZipLen_); + + // Try again + err = UnZip(zlibStream_->next_in, zlibStream_->avail_in, ppUnZipData, ulUnZipLen, iRecursion + 1); + } + else if ((err == Z_OK) && (zlibStream_->avail_in == 0)) { + // All available input has been processed, everything ok. + // Set the size to the amount unzipped in this call (including all recursive calls) + (*ulUnZipLen) = (zlibStream_->total_out - unZipLen_); + unZipLen_ = zlibStream_->total_out; + } + + if (err != Z_OK) + (*ulUnZipLen) = 0; + return err; +} + + +} // namespace net diff --git a/pub/net/packet_process_assist.h b/pub/net/packet_process_assist.h new file mode 100644 index 0000000..fb9023d --- /dev/null +++ b/pub/net/packet_process_assist.h @@ -0,0 +1,104 @@ +// Copyright (c) 2016-2017 The KID Authors. All rights reserved. +// Created on: 2016年12月30日 Author: kerry + +#ifndef SWP_PUB_LOGIC_NET_CHECKSUM_H_ +#define SWP_PUB_LOGIC_NET_CHECKSUM_H_ + +#include +#include "zlib.h" +#include "basic/basictypes.h" + + +#ifdef __ANDROID__ +#ifdef __cplusplus +extern "C"{ +#endif + +unsigned int GetKey(); +void SetKey(unsigned int key); +unsigned int CreateKey(); + +#ifdef __cplusplus +} +#endif +#endif + +namespace net { + +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +typedef unsigned char BYTE; + +enum zip_type { + NO_ZIP_TYPE = 0, + ZIP_TYPE +}; + +enum encrypt_type { + NO_ENCRYPT_TYPE = 0, + TEA +}; + +#define ENCODE_ZLIB_MIN_COMP_SIZE (17) + +bool checksum(const char* src_data, uint16& check_ret); + +#ifndef __ANDROID__ + +unsigned int GetKey(); +void SetKey(unsigned int key); +unsigned int CreateKey(); + +#endif + +//jiami +char* str_en_8byte(char *clearmsg, int len, int rounds, int& len1); +//jiemi +char* str_de_8byte(char *encryptedmsg, int len, int rounds); + +//fengzhuang +std::string str_en(std::string a, int rounds); + +std::string str_de(std::string strEn, int rounds); + +enum +{ + ZIP_TYPE_NONE = 0, + ZIP_TYPE_ZLIB +}; + +class MZip +{ +public: + MZip(void); + virtual ~MZip(void); + + unsigned long ZipData(const unsigned char* pUnZipData, unsigned long ulUnZipLen, unsigned char** ppZipData); + void EnableCompress(bool bEnable); + int Zip(const unsigned char* pUnZipData, unsigned long ulUnZipLen, unsigned char* pZipData, unsigned long& ulZipLen); + +public: + z_stream* zlibStream_; + unsigned long ulTotalZipLen_; + bool bCompress_; +}; + +class MUnZip +{ +public: + MUnZip(void); + virtual ~MUnZip(void); + + unsigned long UnZipData(const unsigned char* pZipData, unsigned long ulZipLen, unsigned char** ppUnZipData); + int UnZip(const unsigned char* pZipData, unsigned long ulZipLen, unsigned char** ppUnZipData, unsigned long* ulUnZipLen, int iRecursion=0); +public: + z_stream * zlibStream_; + unsigned long unZipLen_; +}; + + +} // namespace net + +#endif + diff --git a/pub/net/packet_processing.cc b/pub/net/packet_processing.cc index 843d301..836aeed 100755 --- a/pub/net/packet_processing.cc +++ b/pub/net/packet_processing.cc @@ -4,6 +4,7 @@ #include "net/packet_processing.h" #include "logic/logic_comm.h" #include "net/comm_head.h" +#include "net/packet_process_assist.h" #include "protocol/data_packet.h" #include #include @@ -12,7 +13,16 @@ namespace net { -bool PacketProsess::PacketStream(const PacketHead *packet_head, +void printstream(void* pc, int16 len) { + void* tempCP = pc; + for(int i=1; i<=len; ++i) { + LOG_DEBUG2("[%x]", (*((char*)tempCP) & 0xFF)); + tempCP = (char*)tempCP+1; + } + +} + +bool PacketProsess::PacketClearStream(const PacketHead *packet_head, void **packet_stream, int32 *packet_stream_length) { bool r = true; @@ -44,6 +54,8 @@ bool PacketProsess::PacketStream(const PacketHead *packet_head, *packet_stream = reinterpret_cast(const_cast(out.GetData())); *packet_stream_length = PACKET_HEAD_LENGTH + body_stream.length(); + + if (engine) { delete engine; engine = NULL; @@ -51,7 +63,7 @@ bool PacketProsess::PacketStream(const PacketHead *packet_head, return true; } -bool PacketProsess::UnpackStream(const void *packet_stream, int32 len, +bool PacketProsess::UnpackClearStream(const void *packet_stream, int32 len, struct PacketHead **packet_head) { int32 temp; @@ -118,6 +130,253 @@ bool PacketProsess::UnpackStream(const void *packet_stream, int32 len, return true; } + +bool PacketProsess::PacketStream(const PacketHead *packet_head, + void **packet_stream, + int32 *packet_stream_length) { + bool r = true; + int16 packet_length = packet_head->packet_length; + //int8 is_zip_encrypt = (TEA<<4) + ZIP_TYPE; //高4位加密类型 低4位压缩类型 TODO:一定加密, 选择性压缩 + int8 is_zip_encrypt = (TEA<<4) ; + int8 type = packet_head->type; + //uint16 signature = packet_head->signature; + uint16 signature = 0; + int16 operate_code = packet_head->operate_code; + int16 data_length = packet_head->data_length; + int32 timestamp = packet_head->timestamp; + int64 session_id = packet_head->session_id; + int32 reserved = packet_head->reserved; + + std::string body_stream; + struct PacketControl *packet_control = (struct PacketControl *)(packet_head); + base_logic::DictionaryValue *value = packet_control != NULL ? packet_control->body_ : NULL; + + base_logic::ValueSerializer *engine = base_logic::ValueSerializer::Create( + base_logic::IMPL_JSON); + if (engine == NULL) { + LOG_ERROR("engine create null"); + return false; + } + r = engine->Serialize((*value), &body_stream); + + //加密算法会补全8 位,导致checksum 结果变化,提前补足 + int32 packetBody_length = PACKET_HEAD_LENGTH + body_stream.length() - sizeof(int16) - sizeof(int8); + if (packetBody_length%8 != 0) { + packetBody_length = (packetBody_length/8 + 1) * 8 + sizeof(int16) + sizeof(int8) - PACKET_HEAD_LENGTH; + body_stream.resize(packetBody_length, '\0'); + } else { + packetBody_length = body_stream.length(); + } + LOG_DEBUG2("PacketStream packetBody_length:%d, content:%s", packetBody_length, body_stream.c_str()); + + //1.组明文包 + //BUILDPAKCET(packetBody_length); + data_length = packetBody_length; + packet_length = data_length + PACKET_HEAD_LENGTH; + packet::DataOutPacket out(false, packet_length); + out.Write16(packet_length); + out.Write8(is_zip_encrypt); + out.Write8(type); + out.Write16(signature); + out.Write16(operate_code); + out.Write16(data_length); + out.Write32(timestamp); + out.Write64(session_id); + out.Write32(reserved); + out.WriteData(body_stream.c_str(), packetBody_length); + + char* packetBody_stream; + //2.对明文包checksum,写入signature + char* checksum_packetBody = reinterpret_cast(const_cast(out.GetData())); + if(!checksum(checksum_packetBody, signature)) { + LOG_ERROR("PacketStream checksum failure."); + } + out.Reset(); + out.Skip( sizeof(int16) + sizeof(int8) + sizeof(int8) ); + out.Write16(signature); + LOG_DEBUG2("PacketStream packet_length[%d] is_zip_encrypt[%d] signature [%d]", + packet_length, is_zip_encrypt, signature); + + + //4.加密 + char* encrypt_packetBody = \ + reinterpret_cast(const_cast(out.GetData())) + sizeof(int16) + sizeof(int8); + //LOG_ERROR2("====befor encrypt str[%s]", encrypt_packetBody); + int32 temp_data_len = packet_length - sizeof(int16) - sizeof(int8); + packetBody_stream = str_en_8byte(encrypt_packetBody, temp_data_len, 16, packetBody_length);//Don't forget free memory + //LOG_DEBUG2("====encrypt in len[%d], return length[%d]", temp_data_len, packetBody_length); + + + //3.压缩 TODO: 包体小的时候不压缩,节省时间. 先不压缩 +/* unsigned char* zipData; + unsigned char* zip_packetBody = reinterpret_cast(packetBody_stream); + MZip* zip_handle = new MZip();//TODO: create once + unsigned long zipSize = zip_handle->ZipData(zip_packetBody, packetBody_length, &zipData); + delete zip_handle; + zip_handle = NULL; + LOG_DEBUG2("after zip, data size[%d]", zipSize); + + packetBody_stream = reinterpret_cast(zipData); + packetBody_length = zipSize; + LOG_ERROR2("after zip, body length[%d]", packetBody_length); + */ + + //5.重新组包 + packet_length = packetBody_length + sizeof(int16) + sizeof(int8); + packet::DataOutPacket out_packet(false, packet_length); + out_packet.Write16(packet_length); + out_packet.Write8(is_zip_encrypt); + out_packet.WriteData(packetBody_stream, packetBody_length); + + *packet_stream = reinterpret_cast(const_cast(out_packet.GetData())); + *packet_stream_length = packet_length; + LOG_DEBUG2("PacketStream after packet length[%d]", packet_length); + //printstream(*packet_stream, packet_length); + + if (packetBody_stream) { + delete packetBody_stream; + packetBody_stream = NULL; + } + if (engine) { + delete engine; + engine = NULL; + } + + return true; +} + +bool PacketProsess::UnpackStream(const void *packet_stream, int32 len, + struct PacketHead **packet_head) { + + bool r = false; + int32 temp; + + packet::DataInPacket in( + reinterpret_cast(const_cast(packet_stream)), len); + int16 packet_length = in.Read16(); + int8 is_zip_encrypt = in.Read8(); + LOG_DEBUG2("UnpackStream len[%d],packet length[%d],is_zip_encrypt[%d]", len, packet_length, is_zip_encrypt); + + char* body_stream; + int32 body_length = packet_length - sizeof(int16) - sizeof(int8); + //1.判断是否需要解压 + if((is_zip_encrypt & 0xF) > 0) { + unsigned char* zip_packetBody = \ + reinterpret_cast(const_cast(in.ReadData(temp))); + unsigned char* unzipData; + MUnZip* unzip_handle = new MUnZip();//TODO:Create once + body_length = unzip_handle->UnZipData(zip_packetBody, body_length, &unzipData); + body_stream = reinterpret_cast(unzipData); + delete unzip_handle; + unzip_handle = NULL; + } else { + body_stream = reinterpret_cast(const_cast(in.ReadData(temp))); + } + //LOG_DEBUG2("UnpackStream after unzip body length[%d]", body_length); + + //2.判断是否需要解密 + if(((is_zip_encrypt>>4) & 0xF) > 0) { + char* decrypt_packetBody = reinterpret_cast(body_stream); + body_stream = str_de_8byte(decrypt_packetBody, body_length, 16);//Don't forget free memory + } else { + //body_stream = reinterpret_cast(const_cast(in.ReadData(temp))); + //body_length = len - sizeof(int16) - sizeof(int8); + } + //LOG_DEBUG2("UnpackStream after decrypt body length[%d]", body_length); + + + //3.解包 + packet::DataInPacket in_body_stream(reinterpret_cast(body_stream), body_length); + int8 type = in_body_stream.Read8(); + uint16 signature = in_body_stream.Read16();//原包中签名 + int16 operate_code = in_body_stream.Read16(); + int16 data_length = in_body_stream.Read16(); + int32 timestamp = in_body_stream.Read32(); + int64 session_id = in_body_stream.Read64(); + int32 reserved = in_body_stream.Read32(); + LOG_DEBUG2("===test type[%d], signature[%d], operate_code[%d], data_length[%d],timestamp[%d],session_id[%ld],reserved[%d]", + type,signature,operate_code,data_length,timestamp,session_id,reserved); + + + //4.重新组包 TODO:如果包大小没有变化,可以不组 + packet_length = body_length + sizeof(int16) + sizeof(int8); + packet::DataOutPacket checksum_packet(false, packet_length); + checksum_packet.Write16(packet_length); + checksum_packet.Write8(is_zip_encrypt); + checksum_packet.WriteData(body_stream, body_length); + //签名重置为0 + checksum_packet.Reset(); + checksum_packet.Skip( sizeof(int16) + sizeof(int8) + sizeof(int8) ); + checksum_packet.Write16(0); + + + //5.checksum 校验 + uint16 server_signature; + char* checksum_packetBody = reinterpret_cast(const_cast(checksum_packet.GetData())); + checksum(checksum_packetBody, server_signature); + //LOG_DEBUG2("Original signature[%d], myself signature[%d]", signature, server_signature); + if(0 != signature && server_signature != signature) { + LOG_ERROR2("Original signature[%d], server signature[%d], it's not correct packet.", signature, server_signature); + r = false; + goto UNPAKBACK; + } + + + //6.解析包体, 返回明文 + if (packet_length > PACKET_HEAD_LENGTH) { + std::string body_stream_str = in_body_stream.ReadData(data_length, temp); + LOG_DEBUG2("UnpackStream body_stream[%s]", body_stream_str.c_str()); + int error_code; + std::string error_str; + base_logic::ValueSerializer *engine = base_logic::ValueSerializer::Create( + base_logic::IMPL_JSON); + if (engine == NULL) { + LOG_ERROR("engine create null"); + r = false; + goto UNPAKBACK; + } + + + base_logic::DictionaryValue *value = (base_logic::DictionaryValue*) engine + ->Deserialize(&body_stream_str, &error_code, &error_str); + + if (value == NULL) { + LOG_ERROR2("json error, error_code[%d]", error_code); + r = false; + goto UNPAKBACK; + } + + struct PacketControl *packet_control = new struct PacketControl; + FILLPACKET() + ; + (*packet_head) = (struct PacketHead*) (packet_control); + if (engine) { + delete engine; + engine = NULL; + } + } else if (packet_length == PACKET_HEAD_LENGTH) { + (*packet_head) = new struct PacketHead; + (*packet_head)->packet_length = packet_length; + (*packet_head)->is_zip_encrypt = is_zip_encrypt; + (*packet_head)->type = type; + (*packet_head)->signature = signature; + (*packet_head)->operate_code = operate_code; + (*packet_head)->data_length = data_length; + (*packet_head)->timestamp = timestamp; + (*packet_head)->session_id = session_id; + (*packet_head)->reserved = reserved; + } + + r = true; + goto UNPAKBACK; + +UNPAKBACK: if (((is_zip_encrypt>>4) & 0xF) > 0 && body_stream) { + delete body_stream; + body_stream = NULL; + } + return r; +} + void PacketProsess::DeletePacket(const void *packet_stream, int32 len, struct PacketHead *packet_head){ @@ -153,6 +412,7 @@ uint64 PacketProsess::DecompressionStream(const uint8 *zip_data, uint64 zip_len, } std::string PacketProsess::StrUnpacket(const void *packet_stream, int32 len) { + //TODO: 参照 UnpackStream 写个解密返回包体函数 int32 temp = 0; std::string empty; packet::DataInPacket in( @@ -225,3 +485,5 @@ void PacketProsess::HexEncode(const void *bytes, size_t size) { } } // namespace net + + diff --git a/pub/net/packet_processing.h b/pub/net/packet_processing.h index cd229f0..cab398d 100755 --- a/pub/net/packet_processing.h +++ b/pub/net/packet_processing.h @@ -94,12 +94,23 @@ namespace net { class PacketProsess { public: + //加密压缩组包 static bool PacketStream(const struct PacketHead *packet_head, void **packet_stream, int32 *packet_stream_length); + //解加密压缩包 static bool UnpackStream(const void *packet_stream, int32 len, struct PacketHead **packet_head); + //明文组包 + static bool PacketClearStream(const PacketHead *packet_head, + void **packet_stream, + int32 *packet_stream_length); + + //解明文包 + static bool UnpackClearStream(const void *packet_stream, int32 len, + struct PacketHead **packet_head); + static void HexEncode(const void *bytes, size_t size); static void DumpPacket(const struct PacketHead *packet_head); @@ -123,6 +134,7 @@ class PacketProsess { static uint64 DecompressionStream(const uint8 *zip_data, uint64 zip_len, uint8 **unzip_data); // 解压缩 + }; } // namespace net #endif /* SWP_NET_PACKET_PROCESSING_H_ */