@@ -110,16 +110,36 @@ func _on_forget_password_button_pressed():
|
||||
|
||||
# 处理登录按钮点击
|
||||
func _on_login_button_pressed():
|
||||
var user_name = username_input.text.strip_edges()
|
||||
password_2.hide()
|
||||
verification_code.hide()
|
||||
player_name.hide()
|
||||
farm_name.hide()
|
||||
|
||||
|
||||
|
||||
var user_name = username_input.text.strip_edges() # 修剪前后的空格
|
||||
var user_password = password_input.text.strip_edges()
|
||||
var farmname = farmname_input.text.strip_edges()
|
||||
|
||||
# 验证输入
|
||||
if not _validate_login_input(user_name, user_password, status_label):
|
||||
if user_name == "" or user_password == "":
|
||||
status_label.text = "用户名或密码不能为空!"
|
||||
status_label.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接
|
||||
if not await _ensure_network_connection(status_label):
|
||||
return
|
||||
# 检查网络连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label.text = "未连接到服务器,正在尝试连接..."
|
||||
status_label.modulate = Color.YELLOW
|
||||
# 尝试自动连接到服务器
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# 再次检查连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label.text = "连接服务器失败,正在尝试其他服务器..."
|
||||
status_label.modulate = Color.YELLOW
|
||||
# 等待自动服务器切换完成
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
|
||||
# 禁用按钮,防止重复点击
|
||||
@@ -149,14 +169,31 @@ func _on_login_button_pressed():
|
||||
func _on_send_button_pressed():
|
||||
var user_name = register_username_input.text.strip_edges()
|
||||
|
||||
# 验证输入
|
||||
if not _validate_qq_input(user_name, status_label_2):
|
||||
if user_name == "":
|
||||
status_label_2.text = "请输入QQ号以接收验证码!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接
|
||||
if not await _ensure_network_connection(status_label_2):
|
||||
if !is_valid_qq_number(user_name):
|
||||
status_label_2.text = "请输入正确的QQ号码(5-12位数字)!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_2.text = "未连接到服务器,正在尝试连接..."
|
||||
status_label_2.modulate = Color.YELLOW
|
||||
# 尝试自动连接到服务器
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# 再次检查连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_2.text = "连接服务器失败,正在尝试其他服务器..."
|
||||
status_label_2.modulate = Color.YELLOW
|
||||
# 等待自动服务器切换完成
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
|
||||
# 禁用按钮,防止重复点击
|
||||
send_button.disabled = true
|
||||
@@ -186,18 +223,55 @@ func _on_send_button_pressed():
|
||||
func _on_register_button_2_pressed():
|
||||
var user_name = register_username_input.text.strip_edges()
|
||||
var user_password = password_input_1.text.strip_edges()
|
||||
var password_confirm = password_input_2.text.strip_edges()
|
||||
var user_password_2 = password_input_2.text.strip_edges()
|
||||
var farmname = farmname_input.text.strip_edges()
|
||||
var player_name = playername_input.text.strip_edges()
|
||||
var farm_name = farmname_input.text.strip_edges()
|
||||
var verification_code = verificationcode_input.text.strip_edges()
|
||||
|
||||
# 验证输入
|
||||
if not _validate_register_input(user_name, user_password, password_confirm, player_name, farm_name, verification_code, status_label_2):
|
||||
# 检查密码格式(只允许数字和字母)
|
||||
if not is_valid_password(user_password):
|
||||
status_label_2.text = "密码只能包含数字和字母!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接
|
||||
if not await _ensure_network_connection(status_label_2):
|
||||
if user_name == "" or user_password == "":
|
||||
status_label_2.text = "用户名或密码不能为空!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
if farmname == "":
|
||||
status_label_2.text = "农场名称不能为空!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
if user_password != user_password_2:
|
||||
status_label_2.text = "两次输入的密码不一致!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
if !is_valid_qq_number(user_name):
|
||||
status_label_2.text = "请输入正确的QQ号码(5-12位数字)!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
if verification_code == "":
|
||||
status_label_2.text = "请输入验证码!"
|
||||
status_label_2.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_2.text = "未连接到服务器,正在尝试连接..."
|
||||
status_label_2.modulate = Color.YELLOW
|
||||
# 尝试自动连接到服务器
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# 再次检查连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_2.text = "连接服务器失败,正在尝试其他服务器..."
|
||||
status_label_2.modulate = Color.YELLOW
|
||||
# 等待自动服务器切换完成
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
|
||||
# 禁用按钮,防止重复点击
|
||||
register_button_2.disabled = true
|
||||
@@ -206,7 +280,12 @@ func _on_register_button_2_pressed():
|
||||
status_label_2.modulate = Color.YELLOW
|
||||
|
||||
# 发送注册请求
|
||||
tcp_network_manager_panel.sendRegisterInfo(user_name, user_password, player_name, farm_name, verification_code)
|
||||
tcp_network_manager_panel.sendRegisterInfo(user_name, user_password, farmname, player_name, verification_code)
|
||||
|
||||
# 更新主游戏数据
|
||||
main_game.user_name = user_name
|
||||
main_game.user_password = user_password
|
||||
# farmname 直接在注册成功后通过UI更新,这里不需要设置
|
||||
|
||||
# 5秒后重新启用按钮(如果没有收到响应)
|
||||
await get_tree().create_timer(5.0).timeout
|
||||
@@ -219,14 +298,31 @@ func _on_register_button_2_pressed():
|
||||
func _on_forget_send_button_pressed():
|
||||
var user_name = forget_username_input.text.strip_edges()
|
||||
|
||||
# 验证输入
|
||||
if not _validate_qq_input(user_name, status_label_3):
|
||||
if user_name == "":
|
||||
status_label_3.text = "请输入QQ号以接收验证码!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接
|
||||
if not await _ensure_network_connection(status_label_3):
|
||||
if !is_valid_qq_number(user_name):
|
||||
status_label_3.text = "请输入正确的QQ号码(5-12位数字)!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_3.text = "未连接到服务器,正在尝试连接..."
|
||||
status_label_3.modulate = Color.YELLOW
|
||||
# 尝试自动连接到服务器
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# 再次检查连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_3.text = "连接服务器失败,正在尝试其他服务器..."
|
||||
status_label_3.modulate = Color.YELLOW
|
||||
# 等待自动服务器切换完成
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
# 禁用按钮,防止重复点击
|
||||
forget_send_button.disabled = true
|
||||
|
||||
@@ -257,14 +353,42 @@ func _on_forget_password_confirm_pressed():
|
||||
var new_password = new_password_input.text.strip_edges()
|
||||
var verification_code = forget_verificationcode_input.text.strip_edges()
|
||||
|
||||
# 验证输入
|
||||
if not _validate_forget_password_input(user_name, new_password, verification_code, status_label_3):
|
||||
# 检查密码格式(只允许数字和字母)
|
||||
if not is_valid_password(new_password):
|
||||
status_label_3.text = "密码只能包含数字和字母!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接
|
||||
if not await _ensure_network_connection(status_label_3):
|
||||
if user_name == "" or new_password == "":
|
||||
status_label_3.text = "用户名或新密码不能为空!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
if !is_valid_qq_number(user_name):
|
||||
status_label_3.text = "请输入正确的QQ号码(5-12位数字)!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
if verification_code == "":
|
||||
status_label_3.text = "请输入验证码!"
|
||||
status_label_3.modulate = Color.RED
|
||||
return
|
||||
|
||||
# 检查网络连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_3.text = "未连接到服务器,正在尝试连接..."
|
||||
status_label_3.modulate = Color.YELLOW
|
||||
# 尝试自动连接到服务器
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
|
||||
# 再次检查连接状态
|
||||
if !tcp_network_manager_panel.client.is_client_connected():
|
||||
status_label_3.text = "连接服务器失败,正在尝试其他服务器..."
|
||||
status_label_3.modulate = Color.YELLOW
|
||||
# 等待自动服务器切换完成
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
|
||||
# 禁用按钮,防止重复点击
|
||||
forget_password_button.disabled = true
|
||||
|
||||
@@ -283,138 +407,57 @@ func _on_forget_password_confirm_pressed():
|
||||
|
||||
# 处理验证码发送响应
|
||||
func _on_verification_code_response(success: bool, message: String):
|
||||
_set_status(status_label, message, Color.GREEN if success else Color.RED)
|
||||
if not success:
|
||||
if success:
|
||||
status_label.text = message
|
||||
status_label.modulate = Color.GREEN
|
||||
else:
|
||||
status_label.text = message
|
||||
status_label.modulate = Color.RED
|
||||
send_button.disabled = false
|
||||
send_button.text = "发送验证码"
|
||||
|
||||
# 处理验证码验证响应
|
||||
func _on_verify_code_response(success: bool, message: String):
|
||||
_set_status(status_label, message, Color.GREEN if success else Color.RED)
|
||||
if success:
|
||||
status_label.text = message
|
||||
status_label.modulate = Color.GREEN
|
||||
else:
|
||||
status_label.text = message
|
||||
status_label.modulate = Color.RED
|
||||
|
||||
# 输入验证函数
|
||||
# 验证QQ号是否有效
|
||||
func is_valid_qq_number(qq_number: String) -> bool:
|
||||
# QQ号的标准格式是5到12位的数字
|
||||
var qq_regex = RegEx.new()
|
||||
if qq_regex.compile(r"^\d{5,12}$") != OK:
|
||||
var pattern = r"^\d{5,12}$"
|
||||
|
||||
var error = qq_regex.compile(pattern)
|
||||
if error != OK:
|
||||
status_label.text = "QQ号验证失败部错误"
|
||||
status_label.modulate = Color.RED
|
||||
return false
|
||||
|
||||
return qq_regex.search(qq_number) != null
|
||||
|
||||
# 添加密码验证函数
|
||||
func is_valid_password(password: String) -> bool:
|
||||
return password.match(r"^[a-zA-Z0-9]+$") != null
|
||||
# 使用正则表达式检查是否只包含数字和字母
|
||||
var pattern = r"^[a-zA-Z0-9]+$"
|
||||
return password.match(pattern) != null
|
||||
|
||||
# 处理登录响应
|
||||
func _on_login_response_received(success: bool, message: String, user_data: Dictionary):
|
||||
# 启用按钮
|
||||
login_button.disabled = false
|
||||
|
||||
if success:
|
||||
_set_status(status_label, "登录成功!正在加载游戏...", Color.GREEN)
|
||||
_handle_login_success(user_data)
|
||||
else:
|
||||
_set_status(status_label, "登录失败:" + message, Color.RED)
|
||||
if "密码" in message or "password" in message.to_lower():
|
||||
print("登录失败,可能是密码错误。如需清除保存的登录信息,请调用_clear_login_info()")
|
||||
status_label.text = "登录成功!正在加载游戏..."
|
||||
status_label.modulate = Color.GREEN
|
||||
|
||||
# 处理注册响应
|
||||
func _on_register_response_received(success: bool, message: String):
|
||||
register_button_2.disabled = false
|
||||
|
||||
if success:
|
||||
_set_status(status_label_2, "注册成功!请登录游戏", Color.GREEN)
|
||||
_handle_register_success()
|
||||
else:
|
||||
_set_status(status_label_2, "注册失败:" + message, Color.RED)
|
||||
|
||||
# 处理忘记密码响应
|
||||
func _on_forget_password_response_received(success: bool, message: String):
|
||||
forget_password_button.disabled = false
|
||||
|
||||
if success:
|
||||
_set_status(status_label_3, "密码重置成功!请使用新密码登录", Color.GREEN)
|
||||
_handle_forget_password_success()
|
||||
else:
|
||||
_set_status(status_label_3, "密码重置失败:" + message, Color.RED)
|
||||
|
||||
# 登录信息文件操作
|
||||
func _save_login_info(user_name: String, password: String):
|
||||
_write_login_file({"user_name": user_name, "password": password})
|
||||
print("登录信息已保存" if user_name != "" else "登录信息已清除")
|
||||
|
||||
func _load_login_info():
|
||||
var login_data = _read_login_file()
|
||||
if login_data:
|
||||
var saved_username = login_data.get("user_name", "")
|
||||
var saved_password = login_data.get("password", "")
|
||||
|
||||
if saved_username != "" and saved_password != "":
|
||||
username_input.text = saved_username
|
||||
password_input.text = saved_password
|
||||
_set_status(status_label, "已加载保存的登录信息", Color.CYAN)
|
||||
print("登录信息已加载:用户名 =", saved_username)
|
||||
return
|
||||
|
||||
_set_status(status_label, "欢迎使用萌芽农场", Color.WHITE)
|
||||
print("没有有效的保存登录信息")
|
||||
|
||||
func _clear_login_info():
|
||||
_save_login_info("", "")
|
||||
|
||||
func _write_login_file(data: Dictionary):
|
||||
var file = FileAccess.open("user://login.json", FileAccess.WRITE)
|
||||
if file:
|
||||
file.store_string(JSON.stringify(data, "\t"))
|
||||
file.close()
|
||||
|
||||
func _read_login_file() -> Dictionary:
|
||||
var file = FileAccess.open("user://login.json", FileAccess.READ)
|
||||
if not file:
|
||||
_write_login_file({"user_name": "", "password": ""})
|
||||
return {}
|
||||
|
||||
var json_text = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
if json.parse(json_text) == OK:
|
||||
return json.get_data()
|
||||
return {}
|
||||
|
||||
# 记住密码和快捷登录功能
|
||||
func toggle_remember_password():
|
||||
remember_password = !remember_password
|
||||
print("记住密码选项:", "开启" if remember_password else "关闭")
|
||||
if not remember_password:
|
||||
_clear_login_info()
|
||||
|
||||
func has_saved_login_info() -> bool:
|
||||
var login_data = _read_login_file()
|
||||
return login_data.get("user_name", "") != "" and login_data.get("password", "") != ""
|
||||
|
||||
func quick_login():
|
||||
if has_saved_login_info():
|
||||
var user_name = username_input.text.strip_edges()
|
||||
var user_password = password_input.text.strip_edges()
|
||||
|
||||
if user_name != "" and user_password != "":
|
||||
print("执行快捷登录...")
|
||||
_on_login_button_pressed()
|
||||
else:
|
||||
_set_status(status_label, "保存的登录信息不完整", Color.ORANGE)
|
||||
else:
|
||||
_set_status(status_label, "没有保存的登录信息", Color.ORANGE)
|
||||
|
||||
func get_saved_username() -> String:
|
||||
return _read_login_file().get("user_name", "")
|
||||
|
||||
# 显示版本信息
|
||||
func _display_version_info():
|
||||
if status_label.text in ["欢迎使用萌芽农场", "连接状态"]:
|
||||
_set_status(status_label, "萌芽农场 v" + main_game.client_version + " - 欢迎使用", Color.CYAN)
|
||||
|
||||
|
||||
# 登录成功处理
|
||||
func _handle_login_success(user_data: Dictionary):
|
||||
# 保存登录数据到主游戏
|
||||
main_game.login_data = user_data.duplicate()
|
||||
|
||||
# 保存剩余点赞次数
|
||||
main_game.remaining_likes = user_data.get("今日剩余点赞次数", 10)
|
||||
|
||||
# 更新主游戏数据
|
||||
@@ -423,40 +466,83 @@ func _handle_login_success(user_data: Dictionary):
|
||||
main_game.level = user_data.get("level", 1)
|
||||
main_game.money = user_data.get("money", 0)
|
||||
main_game.stamina = user_data.get("体力值", 20)
|
||||
main_game.show_farm_name.text = "农场名称:" + user_data.get("farm_name", "")
|
||||
main_game.show_player_name.text = "玩家昵称:" + user_data.get("player_name", "")
|
||||
main_game.show_farm_name.text = "农场名称:"+user_data.get("farm_name", "")
|
||||
main_game.show_player_name.text = "玩家昵称:"+user_data.get("player_name", "")
|
||||
farmname_input.text = user_data.get("farm_name", "")
|
||||
|
||||
# 加载各种背包数据
|
||||
# 加载玩家背包数据
|
||||
if user_data.has("player_bag"):
|
||||
main_game.player_bag = user_data.get("player_bag", [])
|
||||
main_game.crop_warehouse = user_data.get("作物仓库", [])
|
||||
main_game.item_bag = user_data.get("道具背包", [])
|
||||
main_game.pet_bag = user_data.get("宠物背包", [])
|
||||
main_game.patrol_pets = user_data.get("巡逻宠物", [])
|
||||
else:
|
||||
main_game.player_bag = []
|
||||
|
||||
# 加载作物仓库数据
|
||||
if user_data.has("作物仓库"):
|
||||
main_game.crop_warehouse = user_data.get("作物仓库", [])
|
||||
else:
|
||||
main_game.crop_warehouse = []
|
||||
|
||||
# 加载道具背包数据
|
||||
if user_data.has("道具背包"):
|
||||
main_game.item_bag = user_data.get("道具背包", [])
|
||||
else:
|
||||
main_game.item_bag = []
|
||||
|
||||
# 加载宠物背包数据
|
||||
if user_data.has("宠物背包"):
|
||||
main_game.pet_bag = user_data.get("宠物背包", [])
|
||||
else:
|
||||
main_game.pet_bag = []
|
||||
|
||||
# 加载巡逻宠物数据
|
||||
if user_data.has("巡逻宠物"):
|
||||
main_game.patrol_pets = user_data.get("巡逻宠物", [])
|
||||
else:
|
||||
main_game.patrol_pets = []
|
||||
|
||||
# 启动游戏并隐藏登录面板
|
||||
main_game.start_game = true
|
||||
self.hide()
|
||||
|
||||
# 更新UI
|
||||
# 确保在更新数据后调用主游戏的 UI 更新函数
|
||||
main_game._update_ui()
|
||||
main_game._refresh_farm_lots()
|
||||
|
||||
player_bag_panel.update_player_bag_ui()
|
||||
# 更新作物仓库和道具背包UI
|
||||
crop_warehouse_panel.update_crop_warehouse_ui()
|
||||
item_bag_panel.update_item_bag_ui()
|
||||
|
||||
# 更新宠物背包UI
|
||||
if pet_bag_panel and pet_bag_panel.has_method("update_pet_bag_ui"):
|
||||
pet_bag_panel.update_pet_bag_ui()
|
||||
|
||||
# 初始化巡逻宠物
|
||||
if main_game.has_method("init_patrol_pets"):
|
||||
main_game.init_patrol_pets()
|
||||
|
||||
# 调用主游戏的登录成功处理函数
|
||||
main_game.handle_login_success(user_data)
|
||||
|
||||
# 初始化游戏设置
|
||||
if main_game.game_setting_panel and main_game.game_setting_panel.has_method("refresh_settings"):
|
||||
main_game.game_setting_panel.refresh_settings()
|
||||
else:
|
||||
status_label.text = "登录失败:" + message
|
||||
status_label.modulate = Color.RED
|
||||
|
||||
# 注册成功处理
|
||||
func _handle_register_success():
|
||||
# 如果登录失败且是密码错误,可以选择清除保存的信息
|
||||
if "密码" in message or "password" in message.to_lower():
|
||||
print("登录失败,可能是密码错误。如需清除保存的登录信息,请调用_clear_login_info()")
|
||||
|
||||
# 处理注册响应
|
||||
func _on_register_response_received(success: bool, message: String):
|
||||
# 启用按钮
|
||||
register_button_2.disabled = false
|
||||
|
||||
if success:
|
||||
status_label_2.text = "注册成功!请登录游戏"
|
||||
status_label_2.modulate = Color.GREEN
|
||||
|
||||
# 注册成功后,如果启用了记住密码,保存登录信息
|
||||
if remember_password:
|
||||
var user_name = register_username_input.text.strip_edges()
|
||||
var user_password = password_input_1.text.strip_edges()
|
||||
@@ -467,15 +553,28 @@ func _handle_register_success():
|
||||
verificationcode_input.text = ""
|
||||
|
||||
# 切换回登录面板
|
||||
_switch_to_login_panel()
|
||||
register_vbox.hide()
|
||||
forget_password_vbox.hide()
|
||||
login_v_box.show()
|
||||
|
||||
# 如果记住密码,自动填充登录信息
|
||||
if remember_password:
|
||||
username_input.text = register_username_input.text
|
||||
password_input.text = password_input_1.text
|
||||
else:
|
||||
status_label_2.text = "注册失败:" + message
|
||||
status_label_2.modulate = Color.RED
|
||||
|
||||
# 忘记密码成功处理
|
||||
func _handle_forget_password_success():
|
||||
# 处理忘记密码响应
|
||||
func _on_forget_password_response_received(success: bool, message: String):
|
||||
# 启用按钮
|
||||
forget_password_button.disabled = false
|
||||
|
||||
if success:
|
||||
status_label_3.text = "密码重置成功!请使用新密码登录"
|
||||
status_label_3.modulate = Color.GREEN
|
||||
|
||||
# 保存新的登录信息
|
||||
if remember_password:
|
||||
var user_name = forget_username_input.text.strip_edges()
|
||||
var new_password = new_password_input.text.strip_edges()
|
||||
@@ -485,84 +584,157 @@ func _handle_forget_password_success():
|
||||
forget_verificationcode_input.text = ""
|
||||
|
||||
# 切换回登录面板并自动填充账号信息
|
||||
_switch_to_login_panel()
|
||||
username_input.text = forget_username_input.text
|
||||
password_input.text = new_password_input.text
|
||||
_set_status(status_label, "密码已重置,请登录", Color.GREEN)
|
||||
|
||||
# 切换到登录面板
|
||||
func _switch_to_login_panel():
|
||||
register_vbox.hide()
|
||||
forget_password_vbox.hide()
|
||||
register_vbox.hide()
|
||||
login_v_box.show()
|
||||
|
||||
# 公共验证函数
|
||||
func _validate_login_input(user_name: String, password: String, label: Label) -> bool:
|
||||
if user_name.is_empty() or password.is_empty():
|
||||
_set_status(label, "用户名或密码不能为空!", Color.RED)
|
||||
return false
|
||||
return true
|
||||
# 自动填充登录信息
|
||||
username_input.text = forget_username_input.text
|
||||
password_input.text = new_password_input.text
|
||||
|
||||
func _validate_register_input(user_name: String, password: String, password_confirm: String, player_name: String, farm_name: String, verification_code: String, label: Label) -> bool:
|
||||
if user_name.is_empty() or password.is_empty() or password_confirm.is_empty() or player_name.is_empty() or farm_name.is_empty():
|
||||
_set_status(label, "所有字段都不能为空!", Color.RED)
|
||||
return false
|
||||
if password != password_confirm:
|
||||
_set_status(label, "两次输入的密码不一致!", Color.RED)
|
||||
return false
|
||||
if not is_valid_qq_number(user_name):
|
||||
_set_status(label, "请输入有效的QQ号(5-12位数字)!", Color.RED)
|
||||
return false
|
||||
if not is_valid_password(password):
|
||||
_set_status(label, "密码只能包含数字和字母!", Color.RED)
|
||||
return false
|
||||
if verification_code.is_empty():
|
||||
_set_status(label, "验证码不能为空!", Color.RED)
|
||||
return false
|
||||
return true
|
||||
status_label.text = "密码已重置,请登录"
|
||||
status_label.modulate = Color.GREEN
|
||||
else:
|
||||
status_label_3.text = "密码重置失败:" + message
|
||||
status_label_3.modulate = Color.RED
|
||||
|
||||
func _validate_qq_input(user_name: String, label: Label) -> bool:
|
||||
if user_name.is_empty():
|
||||
_set_status(label, "请输入QQ号以接收验证码!", Color.RED)
|
||||
return false
|
||||
if not is_valid_qq_number(user_name):
|
||||
_set_status(label, "请输入正确的QQ号码(5-12位数字)!", Color.RED)
|
||||
return false
|
||||
return true
|
||||
# 保存登录信息到JSON文件
|
||||
func _save_login_info(user_name: String, password: String):
|
||||
var login_data = {
|
||||
"user_name": user_name,
|
||||
"password": password
|
||||
}
|
||||
|
||||
func _validate_forget_password_input(user_name: String, new_password: String, verification_code: String, label: Label) -> bool:
|
||||
if user_name.is_empty() or new_password.is_empty():
|
||||
_set_status(label, "用户名或新密码不能为空!", Color.RED)
|
||||
return false
|
||||
if not is_valid_qq_number(user_name):
|
||||
_set_status(label, "请输入正确的QQ号码(5-12位数字)!", Color.RED)
|
||||
return false
|
||||
if not is_valid_password(new_password):
|
||||
_set_status(label, "密码只能包含数字和字母!", Color.RED)
|
||||
return false
|
||||
if verification_code.is_empty():
|
||||
_set_status(label, "请输入验证码!", Color.RED)
|
||||
return false
|
||||
return true
|
||||
var file = FileAccess.open("user://login.json", FileAccess.WRITE)
|
||||
if file:
|
||||
var json_string = JSON.stringify(login_data, "\t")
|
||||
file.store_string(json_string)
|
||||
file.close()
|
||||
print("登录信息已保存")
|
||||
else:
|
||||
print("无法保存登录信息")
|
||||
|
||||
# 公共网络连接检查函数
|
||||
func _ensure_network_connection(label: Label) -> bool:
|
||||
if not tcp_network_manager_panel.client.is_client_connected():
|
||||
_set_status(label, "未连接到服务器,正在尝试连接...", Color.YELLOW)
|
||||
tcp_network_manager_panel.connect_to_current_server()
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
# 从JSON文件加载登录信息
|
||||
func _load_login_info():
|
||||
var file = FileAccess.open("user://login.json", FileAccess.READ)
|
||||
if file:
|
||||
var json_text = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_text)
|
||||
if parse_result == OK:
|
||||
var login_data = json.get_data()
|
||||
if login_data.has("user_name") and login_data.has("password"):
|
||||
var saved_username = login_data.get("user_name", "")
|
||||
var saved_password = login_data.get("password", "")
|
||||
|
||||
if saved_username != "" and saved_password != "":
|
||||
username_input.text = saved_username
|
||||
password_input.text = saved_password
|
||||
status_label.text = "已加载保存的登录信息"
|
||||
status_label.modulate = Color.CYAN
|
||||
print("登录信息已加载:用户名 =", saved_username)
|
||||
else:
|
||||
status_label.text = "欢迎使用萌芽农场"
|
||||
status_label.modulate = Color.WHITE
|
||||
print("没有有效的保存登录信息")
|
||||
else:
|
||||
print("登录信息格式错误")
|
||||
else:
|
||||
print("登录信息JSON解析错误:", json.get_error_message())
|
||||
else:
|
||||
# 创建默认的登录信息文件
|
||||
_save_login_info("", "")
|
||||
status_label.text = "欢迎使用萌芽农场"
|
||||
status_label.modulate = Color.WHITE
|
||||
print("没有找到保存的登录信息,已创建默认文件")
|
||||
|
||||
# 清除保存的登录信息
|
||||
func _clear_login_info():
|
||||
var file = FileAccess.open("user://login.json", FileAccess.WRITE)
|
||||
if file:
|
||||
var empty_data = {
|
||||
"user_name": "",
|
||||
"password": ""
|
||||
}
|
||||
var json_string = JSON.stringify(empty_data, "\t")
|
||||
file.store_string(json_string)
|
||||
file.close()
|
||||
print("登录信息已清除")
|
||||
else:
|
||||
print("无法清除登录信息")
|
||||
|
||||
# 切换记住密码选项
|
||||
func toggle_remember_password():
|
||||
remember_password = !remember_password
|
||||
print("记住密码选项:", "开启" if remember_password else "关闭")
|
||||
|
||||
# 如果关闭了记住密码,清除已保存的信息
|
||||
if not remember_password:
|
||||
_clear_login_info()
|
||||
|
||||
# 检查是否有保存的登录信息
|
||||
func has_saved_login_info() -> bool:
|
||||
var file = FileAccess.open("user://login.json", FileAccess.READ)
|
||||
if file:
|
||||
var json_text = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_text)
|
||||
if parse_result == OK:
|
||||
var login_data = json.get_data()
|
||||
var user_name = login_data.get("user_name", "")
|
||||
var password = login_data.get("password", "")
|
||||
return user_name != "" and password != ""
|
||||
|
||||
if not tcp_network_manager_panel.client.is_client_connected():
|
||||
_set_status(label, "连接服务器失败,正在尝试其他服务器...", Color.YELLOW)
|
||||
await get_tree().create_timer(3.0).timeout
|
||||
return false
|
||||
return true
|
||||
|
||||
# 公共状态设置函数
|
||||
func _set_status(label: Label, text: String, color: Color):
|
||||
label.text = text
|
||||
label.modulate = color
|
||||
# 快捷登录(使用保存的登录信息)
|
||||
func quick_login():
|
||||
if has_saved_login_info():
|
||||
var user_name = username_input.text.strip_edges()
|
||||
var user_password = password_input.text.strip_edges()
|
||||
|
||||
if user_name != "" and user_password != "":
|
||||
print("执行快捷登录...")
|
||||
_on_login_button_pressed()
|
||||
else:
|
||||
status_label.text = "保存的登录信息不完整"
|
||||
status_label.modulate = Color.ORANGE
|
||||
else:
|
||||
status_label.text = "没有保存的登录信息"
|
||||
status_label.modulate = Color.ORANGE
|
||||
|
||||
# 获取保存的用户名(用于调试或显示)
|
||||
func get_saved_username() -> String:
|
||||
var file = FileAccess.open("user://login.json", FileAccess.READ)
|
||||
if file:
|
||||
var json_text = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_text)
|
||||
if parse_result == OK:
|
||||
var login_data = json.get_data()
|
||||
return login_data.get("user_name", "")
|
||||
|
||||
return ""
|
||||
|
||||
# 显示版本信息
|
||||
func _display_version_info():
|
||||
# 在状态标签中显示客户端版本信息
|
||||
if status_label.text == "欢迎使用萌芽农场" or status_label.text == "连接状态":
|
||||
status_label.text = "萌芽农场 v" + main_game.client_version + " - 欢迎使用"
|
||||
status_label.modulate = Color.CYAN
|
||||
|
||||
|
||||
#面板显示与隐藏切换处理
|
||||
func _on_visibility_changed():
|
||||
GlobalVariables.isZoomDisabled = visible
|
||||
if visible:
|
||||
GlobalVariables.isZoomDisabled = true
|
||||
pass
|
||||
else:
|
||||
GlobalVariables.isZoomDisabled = false
|
||||
pass
|
||||
|
||||
@@ -27,7 +27,6 @@ func _ready() -> void:
|
||||
refresh_button.pressed.connect(_on_refresh_button_pressed)
|
||||
confirm_btn.pressed.connect(_on_confirm_btn_pressed)
|
||||
remove_account_btn.pressed.connect(_on_remove_account_btn_pressed)
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
# 初始显示界面数据
|
||||
_refresh_player_info()
|
||||
@@ -37,7 +36,7 @@ func _ready() -> void:
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
_request_player_info_from_server()
|
||||
|
||||
#面板切换显示时
|
||||
|
||||
func _on_visibility_changed():
|
||||
if visible:
|
||||
GlobalVariables.isZoomDisabled = true
|
||||
@@ -217,11 +216,11 @@ func handle_account_response(response_data: Dictionary):
|
||||
var updated_data = response_data["updated_data"]
|
||||
if main_game:
|
||||
if updated_data.has("player_name"):
|
||||
main_game.login_data["player_name"] = updated_data["player_name"]
|
||||
main_game.data["player_name"] = updated_data["player_name"]
|
||||
if updated_data.has("farm_name"):
|
||||
main_game.login_data["farm_name"] = updated_data["farm_name"]
|
||||
main_game.data["farm_name"] = updated_data["farm_name"]
|
||||
if updated_data.has("个人简介"):
|
||||
main_game.login_data["个人简介"] = updated_data["个人简介"]
|
||||
main_game.data["个人简介"] = updated_data["个人简介"]
|
||||
if updated_data.has("user_password"):
|
||||
main_game.user_password = updated_data["user_password"]
|
||||
|
||||
|
||||
@@ -589,75 +589,6 @@ class SMYMongoDBAPI:
|
||||
#=====================在线礼包系统======================
|
||||
|
||||
|
||||
#=====================作物数据系统======================
|
||||
def get_crop_data_config(self) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
获取作物数据配置
|
||||
|
||||
Returns:
|
||||
Dict: 作物数据配置
|
||||
"""
|
||||
try:
|
||||
collection = self.get_collection("gameconfig")
|
||||
|
||||
# 使用已知的文档ID查找
|
||||
object_id = ObjectId("687cfb3d8e77ba00a7414bac")
|
||||
result = collection.find_one({"_id": object_id})
|
||||
|
||||
if result:
|
||||
# 移除MongoDB的_id字段和updated_at字段
|
||||
if "_id" in result:
|
||||
del result["_id"]
|
||||
if "updated_at" in result:
|
||||
del result["updated_at"]
|
||||
|
||||
self.logger.info("成功获取作物数据配置")
|
||||
return result
|
||||
else:
|
||||
self.logger.warning("未找到作物数据配置")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取作物数据配置失败: {e}")
|
||||
return None
|
||||
|
||||
def update_crop_data_config(self, config_data: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
更新作物数据配置
|
||||
|
||||
Args:
|
||||
config_data: 配置数据
|
||||
|
||||
Returns:
|
||||
bool: 是否成功
|
||||
"""
|
||||
try:
|
||||
collection = self.get_collection("gameconfig")
|
||||
|
||||
# 使用已知的文档ID更新
|
||||
object_id = ObjectId("687cfb3d8e77ba00a7414bac")
|
||||
|
||||
# 添加更新时间
|
||||
update_data = {
|
||||
"updated_at": datetime.now(),
|
||||
**config_data
|
||||
}
|
||||
|
||||
result = collection.replace_one({"_id": object_id}, update_data)
|
||||
|
||||
if result.acknowledged and result.matched_count > 0:
|
||||
self.logger.info("成功更新作物数据配置")
|
||||
return True
|
||||
else:
|
||||
self.logger.error("更新作物数据配置失败")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"更新作物数据配置异常: {e}")
|
||||
return False
|
||||
#=====================作物数据系统======================
|
||||
|
||||
|
||||
#=====================道具配置系统======================
|
||||
def get_item_config(self) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
|
||||
@@ -433,7 +433,7 @@ class TCPGameServer(TCPServer):
|
||||
|
||||
#加载作物配置数据(优化版本)
|
||||
def _load_crop_data(self):
|
||||
"""加载作物配置数据(带缓存优化,优先从MongoDB加载)"""
|
||||
"""加载作物配置数据(带缓存优化)"""
|
||||
current_time = time.time()
|
||||
|
||||
# 检查缓存是否有效
|
||||
@@ -442,26 +442,10 @@ class TCPGameServer(TCPServer):
|
||||
return self.crop_data_cache
|
||||
|
||||
# 缓存过期或不存在,重新加载
|
||||
# 优先尝试从MongoDB加载
|
||||
if self.use_mongodb and self.mongo_api:
|
||||
try:
|
||||
crop_data = self.mongo_api.get_crop_data_config()
|
||||
if crop_data:
|
||||
self.crop_data_cache = crop_data
|
||||
self.crop_data_cache_time = current_time
|
||||
self.log('INFO', "成功从MongoDB加载作物数据", 'SERVER')
|
||||
return self.crop_data_cache
|
||||
else:
|
||||
self.log('WARNING', "MongoDB中未找到作物数据,尝试从JSON文件加载", 'SERVER')
|
||||
except Exception as e:
|
||||
self.log('ERROR', f"从MongoDB加载作物数据失败: {str(e)},尝试从JSON文件加载", 'SERVER')
|
||||
|
||||
# MongoDB加载失败或不可用,从JSON文件加载
|
||||
try:
|
||||
with open("config/crop_data.json", 'r', encoding='utf-8') as file:
|
||||
self.crop_data_cache = json.load(file)
|
||||
self.crop_data_cache_time = current_time
|
||||
self.log('INFO', "成功从JSON文件加载作物数据", 'SERVER')
|
||||
return self.crop_data_cache
|
||||
except Exception as e:
|
||||
self.log('ERROR', f"无法加载作物数据: {str(e)}", 'SERVER')
|
||||
@@ -7949,7 +7933,6 @@ class TCPGameServer(TCPServer):
|
||||
|
||||
|
||||
# ================================账户设置处理方法================================
|
||||
#处理修改账号信息请求
|
||||
def _handle_modify_account_info_request(self, client_id, message):
|
||||
"""处理修改账号信息请求"""
|
||||
# 检查用户是否已登录
|
||||
@@ -7978,6 +7961,9 @@ class TCPGameServer(TCPServer):
|
||||
if not new_farm_name:
|
||||
return self._send_modify_account_error(client_id, "农场名称不能为空")
|
||||
|
||||
if len(new_password) < 6:
|
||||
return self._send_modify_account_error(client_id, "密码长度至少6个字符")
|
||||
|
||||
if len(new_player_name) > 20:
|
||||
return self._send_modify_account_error(client_id, "玩家昵称不能超过20个字符")
|
||||
|
||||
@@ -8020,7 +8006,6 @@ class TCPGameServer(TCPServer):
|
||||
self.log('ERROR', f"修改账号信息时出错: {str(e)}", 'ACCOUNT')
|
||||
return self._send_modify_account_error(client_id, "修改账号信息失败,请稍后重试")
|
||||
|
||||
#处理删除账号请求
|
||||
def _handle_delete_account_request(self, client_id, message):
|
||||
"""处理删除账号请求"""
|
||||
# 检查用户是否已登录
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -8,55 +8,8 @@
|
||||
"user_password": "密码",
|
||||
"last_login_time": "2025年07月20日17时19分16秒",
|
||||
"total_login_time": "0时0分0秒",
|
||||
"farm_lots": [
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":true,"is_planted":false,"max_grow_time":3,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0},
|
||||
{"crop_type":"","grow_time":0,"is_dead":false,"is_diged":false,"is_planted":false,"max_grow_time":5,"已浇水":false,"已施肥":false,"土地等级":0}
|
||||
],
|
||||
"last_water_reset_date": "2025-06-05",
|
||||
"farm_lots": [],
|
||||
"player_bag": [],
|
||||
"作物仓库": [],
|
||||
"宠物背包": [],
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{}
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"experience": 455,
|
||||
"level": 36,
|
||||
"money": 200797690,
|
||||
"money": 200797815,
|
||||
"farm_name": "柚大青の小农场",
|
||||
"player_name": "柚大青",
|
||||
"user_name": "2143323382",
|
||||
"user_password": "tyh@19900420",
|
||||
"last_login_time": "2025年07月21日07时50分09秒",
|
||||
"total_login_time": "6时52分47秒",
|
||||
"last_login_time": "2025年07月20日22时15分13秒",
|
||||
"total_login_time": "6时47分9秒",
|
||||
"farm_lots": [
|
||||
{
|
||||
"crop_type": "",
|
||||
@@ -132,27 +132,35 @@
|
||||
},
|
||||
{
|
||||
"crop_type": "杂交树1",
|
||||
"grow_time": 21600,
|
||||
"grow_time": 21042,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 21600,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
"已施肥": true,
|
||||
"土地等级": 3,
|
||||
"施肥时间": 1753019866.8176558,
|
||||
"施肥类型": "农家肥",
|
||||
"施肥倍数": 2.0,
|
||||
"施肥持续时间": 1800,
|
||||
"浇水时间": 1753019871.817958
|
||||
},
|
||||
{
|
||||
"crop_type": "杂交树2",
|
||||
"grow_time": 25254,
|
||||
"grow_time": 21636,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 25200,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
"已施肥": true,
|
||||
"土地等级": 3,
|
||||
"浇水时间": 1753019874.5774846
|
||||
"浇水时间": 1753019874.5774846,
|
||||
"施肥时间": 1753019862.2419734,
|
||||
"施肥类型": "农家肥",
|
||||
"施肥倍数": 2.0,
|
||||
"施肥持续时间": 1800
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
@@ -576,7 +584,7 @@
|
||||
{
|
||||
"name": "胡萝卜",
|
||||
"quality": "普通",
|
||||
"count": 2
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"name": "番茄",
|
||||
@@ -672,15 +680,11 @@
|
||||
"name": "杂交树2",
|
||||
"quality": "传奇",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"name": "大豆",
|
||||
"quality": "普通",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"last_water_reset_date": "2025-06-05",
|
||||
"注册时间": "2025年05月21日15时00分00秒",
|
||||
"个人简介": "其实我是一个梨子,真的,不骗你,hhh",
|
||||
"个人简介": "其实我是一个梨子,真的,不骗你",
|
||||
"作物仓库": [
|
||||
{
|
||||
"name": "番茄",
|
||||
@@ -991,24 +995,24 @@
|
||||
"2025年07月13日07时26分04秒": "金币302 经验63 土豆x5 小麦x3"
|
||||
},
|
||||
"在线礼包": {
|
||||
"当前日期": "2025-07-21",
|
||||
"今日在线时长": 0.0,
|
||||
"当前日期": "2025-07-20",
|
||||
"今日在线时长": 999999.2718074322,
|
||||
"已领取礼包": [],
|
||||
"登录时间": 1753055025.953216
|
||||
"登录时间": 1753003043.7163484
|
||||
},
|
||||
"点赞系统": {
|
||||
"今日剩余点赞次数": 10,
|
||||
"点赞上次刷新时间": "2025-07-21"
|
||||
"点赞上次刷新时间": "2025-07-20"
|
||||
},
|
||||
"新手礼包": {
|
||||
"已领取": true,
|
||||
"领取时间": "2025-07-20 20:21:04"
|
||||
},
|
||||
"体力系统": {
|
||||
"当前体力值": 25,
|
||||
"当前体力值": 24,
|
||||
"最大体力值": 25,
|
||||
"上次刷新时间": "2025-07-21",
|
||||
"上次恢复时间": 1753055025.9496412
|
||||
"上次刷新时间": "2025-07-20",
|
||||
"上次恢复时间": 1753018615.8492067
|
||||
},
|
||||
"道具背包": [
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,118 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
作物数据MongoDB迁移脚本
|
||||
作者: AI Assistant
|
||||
功能: 将crop_data.json中的数据迁移到MongoDB
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from SMYMongoDBAPI import SMYMongoDBAPI
|
||||
|
||||
def migrate_crop_data():
|
||||
"""迁移作物数据到MongoDB"""
|
||||
print("=== 作物数据MongoDB迁移脚本 ===")
|
||||
|
||||
# 1. 连接MongoDB
|
||||
print("\n1. 连接MongoDB...")
|
||||
try:
|
||||
api = SMYMongoDBAPI("mengyafarm") # 使用正式数据库
|
||||
if not api.is_connected():
|
||||
print("❌ MongoDB连接失败")
|
||||
return False
|
||||
print("✅ MongoDB连接成功")
|
||||
except Exception as e:
|
||||
print(f"❌ MongoDB连接异常: {e}")
|
||||
return False
|
||||
|
||||
# 2. 从JSON文件加载作物数据
|
||||
print("\n2. 从JSON文件加载作物数据...")
|
||||
try:
|
||||
with open("config/crop_data.json", 'r', encoding='utf-8') as file:
|
||||
crop_data = json.load(file)
|
||||
print(f"✅ JSON数据加载成功,包含 {len(crop_data)} 种作物")
|
||||
except Exception as e:
|
||||
print(f"❌ 加载JSON文件失败: {e}")
|
||||
return False
|
||||
|
||||
# 3. 检查MongoDB中是否已有数据
|
||||
print("\n3. 检查MongoDB中的现有数据...")
|
||||
try:
|
||||
existing_data = api.get_crop_data_config()
|
||||
if existing_data:
|
||||
print(f"⚠️ MongoDB中已存在作物数据,包含 {len(existing_data)} 种作物")
|
||||
choice = input("是否要覆盖现有数据?(y/N): ").strip().lower()
|
||||
if choice not in ['y', 'yes']:
|
||||
print("取消迁移")
|
||||
return False
|
||||
else:
|
||||
print("✅ MongoDB中暂无作物数据,可以进行迁移")
|
||||
except Exception as e:
|
||||
print(f"❌ 检查MongoDB数据时异常: {e}")
|
||||
return False
|
||||
|
||||
# 4. 迁移数据到MongoDB
|
||||
print("\n4. 迁移数据到MongoDB...")
|
||||
try:
|
||||
success = api.update_crop_data_config(crop_data)
|
||||
if success:
|
||||
print("✅ 作物数据迁移成功")
|
||||
else:
|
||||
print("❌ 作物数据迁移失败")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ 迁移数据时异常: {e}")
|
||||
return False
|
||||
|
||||
# 5. 验证迁移结果
|
||||
print("\n5. 验证迁移结果...")
|
||||
try:
|
||||
migrated_data = api.get_crop_data_config()
|
||||
if migrated_data and len(migrated_data) == len(crop_data):
|
||||
print(f"✅ 迁移验证成功,MongoDB中包含 {len(migrated_data)} 种作物")
|
||||
|
||||
# 检查几个关键作物
|
||||
test_crops = ["小麦", "胡萝卜", "苹果", "松露"]
|
||||
print("\n验证关键作物数据:")
|
||||
for crop_name in test_crops:
|
||||
if crop_name in crop_data and crop_name in migrated_data:
|
||||
original = crop_data[crop_name]
|
||||
migrated = migrated_data[crop_name]
|
||||
if original == migrated:
|
||||
print(f"✅ {crop_name}: 数据一致")
|
||||
else:
|
||||
print(f"⚠️ {crop_name}: 数据不一致")
|
||||
else:
|
||||
print(f"❌ {crop_name}: 数据缺失")
|
||||
else:
|
||||
print("❌ 迁移验证失败")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ 验证迁移结果时异常: {e}")
|
||||
return False
|
||||
|
||||
print("\n=== 迁移完成 ===")
|
||||
print("\n📋 迁移摘要:")
|
||||
print(f" • 源文件: config/crop_data.json")
|
||||
print(f" • 目标数据库: mengyafarm")
|
||||
print(f" • 目标集合: gameconfig")
|
||||
print(f" • 文档ID: 687cfb3d8e77ba00a7414bac")
|
||||
print(f" • 迁移作物数量: {len(crop_data)}")
|
||||
print("\n✅ 作物数据已成功迁移到MongoDB!")
|
||||
print("\n💡 提示: 服务器现在会优先从MongoDB加载作物数据,如果MongoDB不可用会自动回退到JSON文件。")
|
||||
|
||||
return True
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
try:
|
||||
migrate_crop_data()
|
||||
except KeyboardInterrupt:
|
||||
print("\n迁移被用户中断")
|
||||
except Exception as e:
|
||||
print(f"迁移过程中发生异常: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
作物数据MongoDB迁移测试脚本
|
||||
作者: AI Assistant
|
||||
功能: 测试作物数据从JSON到MongoDB的迁移功能
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from SMYMongoDBAPI import SMYMongoDBAPI
|
||||
|
||||
def load_crop_data_from_json():
|
||||
"""从JSON文件加载作物数据"""
|
||||
try:
|
||||
with open("config/crop_data.json", 'r', encoding='utf-8') as file:
|
||||
return json.load(file)
|
||||
except Exception as e:
|
||||
print(f"❌ 加载JSON文件失败: {e}")
|
||||
return None
|
||||
|
||||
def test_crop_data_migration():
|
||||
"""测试作物数据迁移"""
|
||||
print("=== 作物数据MongoDB迁移测试 ===")
|
||||
|
||||
# 1. 连接MongoDB
|
||||
print("\n1. 连接MongoDB...")
|
||||
try:
|
||||
api = SMYMongoDBAPI("test")
|
||||
if not api.is_connected():
|
||||
print("❌ MongoDB连接失败")
|
||||
return False
|
||||
print("✅ MongoDB连接成功")
|
||||
except Exception as e:
|
||||
print(f"❌ MongoDB连接异常: {e}")
|
||||
return False
|
||||
|
||||
# 2. 从JSON文件加载作物数据
|
||||
print("\n2. 从JSON文件加载作物数据...")
|
||||
json_data = load_crop_data_from_json()
|
||||
if not json_data:
|
||||
print("❌ JSON数据加载失败")
|
||||
return False
|
||||
print(f"✅ JSON数据加载成功,包含 {len(json_data)} 种作物")
|
||||
|
||||
# 3. 测试从MongoDB获取作物数据
|
||||
print("\n3. 从MongoDB获取作物数据...")
|
||||
try:
|
||||
mongo_data = api.get_crop_data_config()
|
||||
if mongo_data:
|
||||
print(f"✅ MongoDB数据获取成功,包含 {len(mongo_data)} 种作物")
|
||||
|
||||
# 4. 比较数据一致性
|
||||
print("\n4. 比较数据一致性...")
|
||||
if len(json_data) == len(mongo_data):
|
||||
print("✅ 作物数量一致")
|
||||
else:
|
||||
print(f"⚠️ 作物数量不一致: JSON({len(json_data)}) vs MongoDB({len(mongo_data)})")
|
||||
|
||||
# 检查几个关键作物
|
||||
test_crops = ["小麦", "胡萝卜", "苹果", "松露"]
|
||||
for crop_name in test_crops:
|
||||
if crop_name in json_data and crop_name in mongo_data:
|
||||
json_crop = json_data[crop_name]
|
||||
mongo_crop = mongo_data[crop_name]
|
||||
if json_crop == mongo_crop:
|
||||
print(f"✅ {crop_name} 数据一致")
|
||||
else:
|
||||
print(f"⚠️ {crop_name} 数据不一致")
|
||||
print(f" JSON: {json_crop.get('花费', 'N/A')}元, {json_crop.get('生长时间', 'N/A')}秒")
|
||||
print(f" MongoDB: {mongo_crop.get('花费', 'N/A')}元, {mongo_crop.get('生长时间', 'N/A')}秒")
|
||||
else:
|
||||
print(f"❌ {crop_name} 在某个数据源中缺失")
|
||||
else:
|
||||
print("❌ MongoDB中未找到作物数据")
|
||||
|
||||
# 5. 如果MongoDB中没有数据,尝试更新
|
||||
print("\n5. 尝试更新MongoDB中的作物数据...")
|
||||
try:
|
||||
success = api.update_crop_data_config(json_data)
|
||||
if success:
|
||||
print("✅ 作物数据更新到MongoDB成功")
|
||||
|
||||
# 再次验证
|
||||
print("\n6. 验证更新后的数据...")
|
||||
updated_data = api.get_crop_data_config()
|
||||
if updated_data and len(updated_data) == len(json_data):
|
||||
print("✅ 数据更新验证成功")
|
||||
else:
|
||||
print("❌ 数据更新验证失败")
|
||||
else:
|
||||
print("❌ 作物数据更新到MongoDB失败")
|
||||
except Exception as e:
|
||||
print(f"❌ 更新MongoDB数据时异常: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 从MongoDB获取数据时异常: {e}")
|
||||
return False
|
||||
|
||||
# 7. 测试服务器加载逻辑
|
||||
print("\n7. 测试服务器加载逻辑...")
|
||||
try:
|
||||
# 模拟服务器的加载逻辑
|
||||
from TCPGameServer import TCPGameServer
|
||||
|
||||
# 创建服务器实例(不启动网络服务)
|
||||
server = TCPGameServer()
|
||||
|
||||
# 测试加载作物数据
|
||||
crop_data = server._load_crop_data()
|
||||
if crop_data and len(crop_data) > 0:
|
||||
print(f"✅ 服务器成功加载作物数据,包含 {len(crop_data)} 种作物")
|
||||
|
||||
# 测试几个关键作物
|
||||
test_crops = ["小麦", "胡萝卜"]
|
||||
for crop_name in test_crops:
|
||||
if crop_name in crop_data:
|
||||
crop = crop_data[crop_name]
|
||||
print(f"✅ {crop_name}: {crop.get('花费', 'N/A')}元, {crop.get('生长时间', 'N/A')}秒, {crop.get('品质', 'N/A')}")
|
||||
else:
|
||||
print(f"❌ 服务器数据中缺少 {crop_name}")
|
||||
else:
|
||||
print("❌ 服务器加载作物数据失败")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试服务器加载逻辑时异常: {e}")
|
||||
|
||||
print("\n=== 测试完成 ===")
|
||||
return True
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
try:
|
||||
test_crop_data_migration()
|
||||
except KeyboardInterrupt:
|
||||
print("\n测试被用户中断")
|
||||
except Exception as e:
|
||||
print(f"测试过程中发生异常: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,44 +1,44 @@
|
||||
{
|
||||
"farm_lots": [
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "小麦",
|
||||
"grow_time": 300,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 300,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
"土地等级": 4
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "小麦",
|
||||
"grow_time": 300,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 300,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
"土地等级": 4
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "小麦",
|
||||
"grow_time": 300,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 300,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
"土地等级": 4
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "小麦",
|
||||
"grow_time": 300,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 300,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
@@ -78,11 +78,11 @@
|
||||
"土地等级": 3
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "龙果",
|
||||
"grow_time": 14405,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 14400,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
@@ -397,11 +397,11 @@
|
||||
"土地等级": 0
|
||||
},
|
||||
{
|
||||
"crop_type": "",
|
||||
"grow_time": 0,
|
||||
"crop_type": "野草2",
|
||||
"grow_time": 5,
|
||||
"is_dead": false,
|
||||
"is_diged": true,
|
||||
"is_planted": false,
|
||||
"is_planted": true,
|
||||
"max_grow_time": 5,
|
||||
"已浇水": false,
|
||||
"已施肥": false,
|
||||
@@ -573,15 +573,17 @@
|
||||
"count": 8
|
||||
}
|
||||
],
|
||||
"experience": 852,
|
||||
"experience": 573,
|
||||
"farm_name": "树萌芽の狗窝",
|
||||
"player_name": "树萌芽2",
|
||||
"player_name": "树萌芽",
|
||||
"level": 64,
|
||||
"money": 615197019764,
|
||||
"last_login_time": "2025年07月21日07时37分38秒",
|
||||
"total_login_time": "162时52分10秒",
|
||||
"money": 615197019864,
|
||||
"last_login_time": "2025年07月19日21时52分29秒",
|
||||
"total_login_time": "162时47分40秒",
|
||||
"user_name": "3205788256",
|
||||
"user_password": "tyh@19900420",
|
||||
"last_water_reset_date": "2025-06-06",
|
||||
"last_check_in_date": "2025-06-01",
|
||||
"session_start_time": 1749878790.288913,
|
||||
"个人简介": "人生啊,就这样吧",
|
||||
"注册时间": "2025年05月21日15时00分00秒",
|
||||
@@ -634,7 +636,7 @@
|
||||
{
|
||||
"name": "小麦",
|
||||
"quality": "普通",
|
||||
"count": 34
|
||||
"count": 16
|
||||
},
|
||||
{
|
||||
"name": "山葵",
|
||||
@@ -695,11 +697,6 @@
|
||||
"name": "马铃薯",
|
||||
"quality": "普通",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"name": "火龙果",
|
||||
"quality": "稀有",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"道具背包": [
|
||||
@@ -1100,20 +1097,20 @@
|
||||
"上次护理时间": 1752051799
|
||||
},
|
||||
"体力系统": {
|
||||
"当前体力值": 25,
|
||||
"最大体力值": 25,
|
||||
"上次刷新时间": "2025-07-21",
|
||||
"上次恢复时间": 1753054658.7901437
|
||||
"当前体力值": 20,
|
||||
"最大体力值": 20,
|
||||
"上次刷新时间": "2025-07-19",
|
||||
"上次恢复时间": 1752904756.8787217
|
||||
},
|
||||
"点赞系统": {
|
||||
"今日剩余点赞次数": 10,
|
||||
"点赞上次刷新时间": "2025-07-21"
|
||||
"点赞上次刷新时间": "2025-07-19"
|
||||
},
|
||||
"在线礼包": {
|
||||
"当前日期": "2025-07-21",
|
||||
"当前日期": "2025-07-19",
|
||||
"今日在线时长": 0.0,
|
||||
"已领取礼包": [],
|
||||
"登录时间": 1753054658.793094
|
||||
"登录时间": 1752904756.8793516
|
||||
},
|
||||
"玩家小卖部": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user