public bool CreateGame(SGameRoomItem item) { com.QH.QPGame.GameUtils.Logger.Sys.Log("Create game:" + item.GameNameID); var agent = GetARunningAgent(); if (agent != null) { return(false); } DestoryAgents(); //ClearPlayers(); GC.Collect(); agent = CreateGameAgent(item); if (agent == null) { return(false); } mGameAgentList.Add(agent); if (!agent.Start(item)) { return(false); } return(true); }
//游戏中用户坐下 public void OnSendUserSitInfo(uint uid, ushort desk, ushort chairs) { if (GameApp.GameData.EnterRoomID == 0) { return; } SGameRoomItem item = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (item == null || item.AutoSit) { return; } if (desk != CommonDefine.INVALID_TABLE && chairs != CommonDefine.INVALID_CHAIR) { PlayerInfo temp = GameApp.GameSrv.FindPlayer(uid); HallTransfer.RoomUserInfo tempRoomUserInfo = new HallTransfer.RoomUserInfo(); tempRoomUserInfo.dwUserId = uid; tempRoomUserInfo.dwNickName = temp.NickName; tempRoomUserInfo.dwLogoID = temp.HeadID; tempRoomUserInfo.dwMoney = temp.Money; tempRoomUserInfo.dwDesk = desk; tempRoomUserInfo.dwChair = chairs; tempRoomUserInfo.dwGameCount = 10; //暂时写死 HallTransfer.Instance.cnShowUserInfo(tempRoomUserInfo); //发送进入玩家数据 } }
public void Stop() { UnRegisterEvent(); GameApp.Network.CloseConnect(ConnectionID.Game); if (loaded) { QuitGameScene(); } var config = GameApp.GameMgr.GetGameConfig((int)GameID); if (config != null) { string scene = string.Format(GlobalConst.UI.UI_SCENE_GAME, GameID, config.SceneName); GameApp.ResMgr.UnloadLevel(scene, true); } GameApp.GameSrv.ClearPlayers(); GameApp.GameData.UserInfo.SetSitInfo(CommonDefine.INVALID_TABLE, CommonDefine.INVALID_CHAIR); GameApp.GameData.EnterRoomID = 0; Resources.UnloadUnusedAssets(); instance = null; roomItem = null; }
private void OnConfigServerResp(Packet packet) { int dataStruct = Marshal.SizeOf(typeof(CMD_GR_ConfigServer)); if (packet.DataSize < dataStruct) { Debug.LogWarning("data error!"); return; } CMD_GR_ConfigServer config = GameConvert.ByteToStruct <CMD_GR_ConfigServer>(packet.Data); SGameRoomItem item = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (item != null) { item.GameRule = config.dwServerRule; item.DeskCount = config.wTableCount; item.DeskPeople = config.wChairCount; if ((config.dwServerRule & (uint)CommonDefine.SR_ALLOW_AVERT_CHEAT_MODE) > 0) { item.AutoSit = true; } if ((config.wServerType & (uint)CommonDefine.GAME_GENRE_EDUCATE) > 0) { item.IsEducate = true; } } }
public void AppendRoomItem(SGameRoomItem item) { foreach (var room in _gameList.RoomList) { if (room.ID == item.ID) { _gameList.RoomList.Remove(room); break; } } _gameList.RoomList.Add(item); }
public bool Start(SGameRoomItem room) { oriSize = new Vector2(Screen.width, Screen.height); instance = this; roomItem = room; GameApp.GameData.EnterRoomID = roomItem.ID; RegisterEvent(); var ip = GameApp.Options.EnableServerList ? GameApp.SvrListMgr.PickALowestDelayServer() : roomItem.ServiceIP; GameApp.Network.Connect(ConnectionID.Game, ip, roomItem.ServicePort); return(true); }
private IGameAgent CreateGameAgent(SGameRoomItem item) { IGameAgent agent = null; switch (item.HostType) { case enGameHostType.IPC: { break; } case enGameHostType.Scene: { string strPrefix = item.GameNameID.ToString(); if (strPrefix.Length > 6) { strPrefix = strPrefix.Substring(0, 6); } int prefix = int.Parse(strPrefix); if (mGameAssemblies.ContainsKey(prefix)) { var impl = mGameAssemblies[prefix]; var obj = Activator.CreateInstance(impl); agent = obj as IGameAgent; } else { throw new NotImplementedException("no implemented found by gameid:" + item.GameNameID); } break; } case enGameHostType.Socket: { break; } } return(agent); }
public void OnServerListResp(Packet packet) { switch (packet.SubCmd) { case SubCommand.SUB_GP_LIST_TYPE: { int dataStruct = Marshal.SizeOf(typeof(tagGameType)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameType Game List data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameType)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameType kindDataE = GameConvert.ByteToStruct <tagGameType>(tempDataBB); GameApp.GameListMgr.AppendTypeItem(ProtoHelper.InitGameTypeItem(kindDataE)); //Logger.Sys.Log("Append Game Type===========" + kindDataE.TypeID + " Name:" + kindDataE.TypeName); } ByteBufferPool.DropPacket(listDataBuff); return; } case SubCommand.SUB_GP_LIST_KIND: { int dataStruct = Marshal.SizeOf(typeof(tagGameKind)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameKind Game name list data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameKind)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameKind tempNameS = GameConvert.ByteToStruct <tagGameKind>(tempDataBB); GameApp.GameListMgr.AppendKindItem(ProtoHelper.InitGameKindItem(tempNameS)); //Logger.Sys.Log("Append Game Kind==========="+ tempNameS.KindID +" Name:"+tempNameS.KindName + " Process:"+tempNameS.ProcessName); } ByteBufferPool.DropPacket(listDataBuff); //GameApp.Account.CallGameListFinishEvent(); return; } case SubCommand.SUB_GP_LIST_NODE: { int dataStruct = Marshal.SizeOf(typeof(tagGameNode)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameNode Game List data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameNode)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameNode nodeDataE = GameConvert.ByteToStruct <tagGameNode>(tempDataBB); GameApp.GameListMgr.AppendNodeItem(ProtoHelper.InitGameNodeItem(nodeDataE)); } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallGameListFinishEvent(); return; } case SubCommand.SUB_GP_LIST_SERVER: { int dataStruct = Marshal.SizeOf(typeof(tagGameServer)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameServer Room list data error!"); return; } uint kindID = 0; int dataSzie = Marshal.SizeOf(typeof(tagGameServer)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempData = listDataBuff.PopByteArray(dataSzie); tagGameServer roomInfoS = GameConvert.ByteToStruct <tagGameServer>(tempData); //Logger.Net.Log("--------------ROOM:" + roomInfoS.KindID + " " + roomInfoS.ServerID + " " + roomInfoS.ServerName+" "+roomInfoS.ServerAddr); kindID = roomInfoS.KindID; GameApp.GameListMgr.AppendRoomItem(ProtoHelper.InitGameRoomItem(roomInfoS)); /* if (GameApp.GameData.ReEnter && * GameApp.GameData.ReEnterRoomID == roomInfoS.ServerID) * { * GameApp.GameData.ReEnterNameID = roomInfoS.KindID; * if (ReconnectGameEvent != null) * { * ReconnectGameEvent(roomInfoS.ServerID, false); * } * }*/ } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallRoomListFinishEvent(kindID); return; } case SubCommand.SUB_CS_S_SERVER_ONLINE: { int dataSzie = Marshal.SizeOf(typeof(tagOnLineInfoServer)); if (packet.DataSize < dataSzie) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameServer Room list data error! size:" + packet.DataSize); return; } int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagOnLineInfoServer OnlineDataE = GameConvert.ByteToStruct <tagOnLineInfoServer>(tempDataBB); SGameRoomItem temRoomItem = GameApp.GameListMgr.FindRoomItem((uint)OnlineDataE.wServerID); if (temRoomItem != null) { temRoomItem.UpdateOnlineCnt((uint)OnlineDataE.dwOnLineCount); } } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallOnlineCountEvent(); return; } } }
public void OnStatusResp(Packet packet) { switch (packet.SubCmd) { case SubCommand.SUB_GR_TABLE_INFO: { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); ushort cnt = buffer.PopUInt16(); for (int i = 0; i < cnt; i++) { //GameTable table = new GameTable(); byte TableLock = buffer.PopByte(); byte PlayStatus = buffer.PopByte(); SRoomDeskItem item = new SRoomDeskItem(); item.DeskID = (uint)i; item.Status = PlayStatus; SGameRoomItem room = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (room != null) { room.Desks.Add(item); } /* table.ChairFlag = "0".PadRight((int)GameApp.GameData.EnterRoomItem.DeskPeople, '0'); * table.ChairUsedQty = 0;*/ } ByteBufferPool.DropPacket(buffer); break; } case SubCommand.SUB_GR_TABLE_STATUS: { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); ushort tableID = buffer.PopUInt16(); byte locked = buffer.PopByte(); byte status = buffer.PopByte(); ByteBufferPool.DropPacket(buffer); SGameRoomItem room = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (room != null) { SRoomDeskItem item = room.Desks.Find(deskItem => deskItem.DeskID == tableID); if (item != null) { item.DeskID = (uint)tableID; item.Status = status; GameApp.GameSrv.CallDeskPlayStatuseEvent((UInt32)tableID, status); } } if (status == (byte)TableState.TB_FREE) { GameApp.GameSrv.CallGameEndedEvent(tableID); } else { Debug.Log("Game Start"); GameApp.GameSrv.CallGameStartedEvent(tableID); } break; } } }