public override void addToStream(Bundle stream, object v) { stream.writeUint32((UInt32)((List<object>)v).Count); for(int i=0; i<((List<object>)v).Count; i++) { ((KBEDATATYPE_BASE)type).addToStream(stream, ((List<object>)v)[i]); } }
/* 向服务端发送这个mail */ public void postMail(Bundle inbundle) { if(inbundle == null) inbundle = bundle; inbundle.send(networkInterface_); if(inbundle == bundle) bundle = null; }
/* 创建新的mail */ public Bundle newMail() { if(bundle == null) bundle = new Bundle(); if(type == Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL) bundle.newMessage(Message.messages["Baseapp_onRemoteCallCellMethodFromClient"]); else bundle.newMessage(Message.messages["Base_onRemoteMethodCall"]); bundle.writeInt32(this.id); return bundle; }
private void onLogin_loginapp() { if(!loginappMessageImported_) { var bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onLogin_loginapp: send importClientMessages ..."); Event.fireOut("Loginapp_importClientMessages", new object[]{}); } else { onImportClientMessagesCompleted(); } }
/* 更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayer关闭这个机制 */ public void updatePlayerToServer() { if(!_args.syncPlayer || spaceID == 0) { return; } TimeSpan span = DateTime.Now - _lastUpdateToServerTime; if(span.Milliseconds < 50) return; Entity playerEntity = player(); if(playerEntity == null || playerEntity.inWorld == false) return; _lastUpdateToServerTime = System.DateTime.Now; Vector3 position = playerEntity.position; Vector3 direction = playerEntity.direction; bool posHasChanged = Vector3.Distance(_entityLastLocalPos, position) > 0.001f; bool dirHasChanged = Vector3.Distance(_entityLastLocalDir, direction) > 0.001f; if(posHasChanged || dirHasChanged) { _entityLastLocalPos = position; _entityLastLocalDir = direction; Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_onUpdateDataFromClient"]); bundle.writeFloat(position.x); bundle.writeFloat(position.y); bundle.writeFloat(position.z); bundle.writeFloat((float)((double)direction.x / 360 * 6.283185307179586)); bundle.writeFloat((float)((double)direction.y / 360 * 6.283185307179586)); bundle.writeFloat((float)((double)direction.z / 360 * 6.283185307179586)); bundle.writeUint8((Byte)(playerEntity.isOnGround == true ? 1 : 0)); bundle.writeUint32(spaceID); bundle.send(_networkInterface); } }
/* 重置密码, 通过loginapp */ public void resetpassword_loginapp(bool noconnect) { if(noconnect) { reset(); _networkInterface.connectTo(_args.ip, _args.port, onConnectTo_resetpassword_callback, null); } else { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_reqAccountResetPassword"]); bundle.writeString(username); bundle.send(_networkInterface); } }
public void onOpenLoginapp_resetpassword() { Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_resetpassword: successfully!"); currserver = "loginapp"; currstate = "resetpassword"; if(!loginappMessageImported_) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_resetpassword: send importClientMessages ..."); } else { onImportClientMessagesCompleted(); } }
/* 登录到服务端(loginapp), 登录成功后还必须登录到网关(baseapp)登录流程才算完毕 */ public void login_loginapp(bool noconnect) { if(noconnect) { reset(); _networkInterface.connectTo(_args.ip, _args.port, onConnectTo_loginapp_callback, null); } else { Dbg.DEBUG_MSG("KBEngine::login_loginapp(): send login! username="******"Loginapp_login"]); bundle.writeInt8((sbyte)_args.clientType); bundle.writeBlob(KBEngineApp.app._clientdatas); bundle.writeString(username); bundle.writeString(password); bundle.send(_networkInterface); } }
/* 与服务端握手,与任何一个进程连接之后应该第一时间进行握手 */ public void hello() { Bundle bundle = new Bundle(); if(currserver == "loginapp") bundle.newMessage(Message.messages["Loginapp_hello"]); else bundle.newMessage(Message.messages["Baseapp_hello"]); bundle.writeString(clientVersion); bundle.writeString(clientScriptVersion); bundle.writeBlob(_encryptedKey); bundle.send(_networkInterface); }
public void bindEMail_baseapp() { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_reqAccountBindEmail"]); bundle.writeInt32(entity_id); bundle.writeString(password); bundle.writeString("*****@*****.**"); bundle.send(networkInterface_); }
public override void addToStream(Bundle stream, object v) { stream.writeInt64(Convert.ToInt64(v)); }
public override void addToStream(Bundle stream, object v) { foreach(string itemkey in dicttype.Keys) { ((KBEDATATYPE_BASE)dicttype[itemkey]).addToStream(stream, ((Dictionary<string, object>)v)[itemkey]); } }
public override void addToStream(Bundle stream, object v) { stream.writeBlob((byte[])v); }
public override void addToStream(Bundle stream, object v) { stream.writeBlob(System.Text.Encoding.UTF8.GetBytes((string)v)); }
public void hello() { Bundle bundle = new Bundle(); if(currserver_ == "loginapp") bundle.newMessage(Message.messages["Loginapp_hello"]); else bundle.newMessage(Message.messages["Baseapp_hello"]); bundle.writeString(clientVersion_); bundle.writeBlob(clientdatas_); bundle.send(networkInterface_); }
private void onLogin_loginapp() { currserver_ = "loginapp"; currstate_ = "login"; if(!loginappMessageImported_) { var bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(networkInterface_); Dbg.DEBUG_MSG("KBEngine::onLogin_loginapp: start importClientMessages ..."); Event.fire("Loginapp_importClientMessages", new object[]{}); } else { onImportClientMessagesCompleted(); } }
public bool login_baseapp(bool noconnect) { if(noconnect) { Event.fire("login_baseapp", new object[]{}); if(!networkInterface_.connect(ip, port)) { Dbg.ERROR_MSG(string.Format("KBEngine::login_baseapp(): connect {0}:{1} is error!", ip, port)); return false; } onLogin_baseapp(); Dbg.DEBUG_MSG(string.Format("KBEngine::login_baseapp(): connect {0}:{1} is successfylly!", ip, port)); } else { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_loginGateway"]); bundle.writeString(username); bundle.writeString(password); bundle.send(networkInterface_); } return true; }
/* 创建账号,通过loginapp */ public void createAccount_loginapp(bool noconnect) { if(noconnect) { reset(); _networkInterface.connectTo(_args.ip, _args.port, onConnectTo_createAccount_callback, null); } else { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_reqCreateAccount"]); bundle.writeString(username); bundle.writeString(password); bundle.writeBlob(KBEngineApp.app._clientdatas); bundle.send(_networkInterface); } }
public bool login_loginapp(bool noconnect) { if(noconnect) { reset(); if(!networkInterface_.connect(loginappIP, loginappPort)) { Dbg.ERROR_MSG(string.Format("KBEngine::login_loginapp(): connect {0}:{1} is error!", loginappIP, loginappPort)); return false; } onLogin_loginapp(); Dbg.DEBUG_MSG(string.Format("KBEngine::login_loginapp(): connect {0}:{1} is successfylly!", loginappIP, loginappPort)); } else { Dbg.DEBUG_MSG("KBEngine::login_loginapp(): send login! username="******"Loginapp_login"]); bundle.writeInt8(3); // clientType bundle.writeBlob(new byte[0]); bundle.writeString(username); bundle.writeString(password); bundle.send(networkInterface_); } return true; }
/* 登录到服务端,登录到网关(baseapp) */ public void login_baseapp(bool noconnect) { if(noconnect) { Event.fireOut("onLoginBaseapp", new object[]{}); _networkInterface.reset(); _networkInterface = new NetworkInterface(); _networkInterface.connectTo(baseappIP, baseappPort, onConnectTo_baseapp_callback, null); } else { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_loginBaseapp"]); bundle.writeString(username); bundle.writeString(password); bundle.send(_networkInterface); } }
public void onOpenLoginapp_createAccount() { Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_createAccount: successfully!"); currserver_ = "loginapp"; currstate_ = "createAccount"; if(!loginappMessageImported_) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(networkInterface_); Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_createAccount: start importClientMessages ..."); } else { onImportClientMessagesCompleted(); } }
/* 设置新密码,通过baseapp, 必须玩家登录在线操作所以是baseapp。 */ public void newPassword(string old_password, string new_password) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_reqAccountNewPassword"]); bundle.writeInt32(entity_id); bundle.writeString(old_password); bundle.writeString(new_password); bundle.send(_networkInterface); }
public bool resetpassword_loginapp(bool noconnect) { if(noconnect) { reset(); if(!networkInterface_.connect(ip, port)) { Dbg.ERROR_MSG(string.Format("KBEngine::resetpassword_loginapp(): connect {0}:{1} is error!", ip, port)); return false; } onOpenLoginapp_resetpassword(); Dbg.DEBUG_MSG(string.Format("KBEngine::resetpassword_loginapp(): connect {0}:{1} is successfylly!", ip, port)); } else { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_reqAccountResetPassword"]); bundle.writeString(username); bundle.send(networkInterface_); } return true; }
/* 绑定Email,通过baseapp */ public void bindAccountEmail(string emailAddress) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_reqAccountBindEmail"]); bundle.writeInt32(entity_id); bundle.writeString(password); bundle.writeString(emailAddress); bundle.send(_networkInterface); }
public void sendTick() { if(!networkInterface_.valid()) return; TimeSpan span = DateTime.Now - lastticktime_; updatePlayerToServer(); if(span.Seconds > 15) { if(Message.messages["Loginapp_onClientActiveTick"] != null || Message.messages["Baseapp_onClientActiveTick"] != null) { Bundle bundle = new Bundle(); if(currserver_ == "loginapp") { bundle.newMessage(Message.messages["Loginapp_onClientActiveTick"]); } else { bundle.newMessage(Message.messages["Baseapp_onClientActiveTick"]); } bundle.send(networkInterface_); } lastticktime_ = System.DateTime.Now; } }
/* 向服务端发送心跳以及同步角色信息到服务端 */ public void sendTick() { if(!_networkInterface.valid()) return; if(!loginappMessageImported_ && !baseappMessageImported_) return; TimeSpan span = DateTime.Now - _lastticktime; // 更新玩家的位置与朝向到服务端 updatePlayerToServer(); if(span.Seconds > 15) { Message Loginapp_onClientActiveTickMsg = null; Message Baseapp_onClientActiveTickMsg = null; Message.messages.TryGetValue("Loginapp_onClientActiveTick", out Loginapp_onClientActiveTickMsg); Message.messages.TryGetValue("Baseapp_onClientActiveTick", out Baseapp_onClientActiveTickMsg); if(currserver == "loginapp") { if(Loginapp_onClientActiveTickMsg != null) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_onClientActiveTick"]); bundle.send(_networkInterface); } } else { if(Baseapp_onClientActiveTickMsg != null) { Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_onClientActiveTick"]); bundle.send(_networkInterface); } } _lastticktime = System.DateTime.Now; } }
public bool autoImportMessagesFromServer(bool isLoginapp) { reset(); if(!networkInterface_.connect(ip, port)) { Dbg.ERROR_MSG(string.Format("KBEngine::autoImportMessagesFromServer(): connect {0}:{1} is error!", ip, port)); return false; } if(isLoginapp) { currserver_ = "loginapp"; currstate_ = "autoimport"; if(!loginappMessageImported_) { var bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(networkInterface_); Dbg.DEBUG_MSG("KBEngine::autoImportMessagesFromServer: start importClientMessages ..."); } else { onImportClientMessagesCompleted(); } } else{ currserver_ = "baseapp"; currstate_ = "autoimport"; if(!baseappMessageImported_) { var bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_importClientMessages"]); bundle.send(networkInterface_); Dbg.DEBUG_MSG("KBEngine::autoImportMessagesFromServer: start importClientMessages ..."); } else { onImportClientMessagesCompleted(); } } Dbg.DEBUG_MSG(string.Format("KBEngine::autoImportMessagesFromServer(): connect {0}:{1} is successfylly!", ip, port)); return true; }
/* 从二进制流导入消息协议完毕了 */ private void onImportClientMessagesCompleted() { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted: successfully! currserver=" + currserver + ", currstate=" + currstate); if(currserver == "loginapp") { if(!isImportServerErrorsDescr_ && !loadingLocalMessages_) { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); isImportServerErrorsDescr_ = true; Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importServerErrorsDescr"]); bundle.send(_networkInterface); } if(currstate == "login") { login_loginapp(false); } else if(currstate == "autoimport") { } else if(currstate == "resetpassword") { resetpassword_loginapp(false); } else if(currstate == "createAccount") { createAccount_loginapp(false); } else{ } loginappMessageImported_ = true; } else { baseappMessageImported_ = true; if(!entitydefImported_ && !loadingLocalMessages_) { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted: send importEntityDef(" + entitydefImported_ + ") ..."); Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_importClientEntityDef"]); bundle.send(_networkInterface); Event.fireOut("Baseapp_importClientEntityDef", new object[]{}); } else { onImportEntityDefCompleted(); } } }
private void onImportClientMessagesCompleted() { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted: successfully! currserver=" + currserver_ + ", currstate=" + currstate_); hello(); if(currserver_ == "loginapp") { if(isImportMercuryErrorsDescr_ == false) { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted(): start importMercuryErrorsDescr!"); isImportMercuryErrorsDescr_ = true; Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Loginapp_importMercuryErrorsDescr"]); bundle.send(networkInterface_); } if(currstate_ == "login") { login_loginapp(false); } else if(currstate_ == "autoimport") { } else if(currstate_ == "resetpassword") { resetpassword_loginapp(false); } else { createAccount_loginapp(false); } loginappMessageImported_ = true; } else { baseappMessageImported_ = true; if(entitydefImported_ == false) { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted: start importEntityDef ..."); Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_importClientEntityDef"]); bundle.send(networkInterface_); Event.fire("Baseapp_importClientEntityDef", new object[]{}); } else { onImportEntityDefCompleted(); } } }
private void onReConnectTo_baseapp_callback(string ip, int port, bool success, object userData) { if(!success) { Dbg.ERROR_MSG(string.Format("KBEngine::reLoginBaseapp(): connect {0}:{1} is error!", ip, port)); return; } Dbg.DEBUG_MSG(string.Format("KBEngine::relogin_baseapp(): connect {0}:{1} is successfully!", ip, port)); Bundle bundle = new Bundle(); bundle.newMessage(Message.messages["Baseapp_reLoginBaseapp"]); bundle.writeString(username); bundle.writeString(password); bundle.writeUint64(entity_uuid); bundle.writeInt32(entity_id); bundle.send(_networkInterface); }
public static void ReturnBundle(Bundle bundle) { bundle.Reset(); pool.Enqueue(bundle); }