private void CommandHandle_ClientClose(IPEndPoint remoteIp, NetInputData package) { //携带的玩家索引为空 if (package.PlayerIndex == NetInputData.PlayerIndexEmpty) { return; } Monitor.Enter(netPlayerList); try { //尝试清除一次分配列表内的信息 RemovePlayerFromSelectList(remoteIp); NetInputPlayer player = getNetPlayer(package.PlayerIndex); //检测这个用户是否激活了。并且和客户端是匹配的 if (player != null && player.isActive && player.remoteIp != null && player.remoteIp.Equals(remoteIp)) { //注销这个客户端位置 player.SetActive(false, null); } } catch (System.Exception ex) { } Monitor.Exit(netPlayerList); }
//分配一个位置给客户端 private void AllocationPlayerPosition(IPEndPoint remoteIp, int index) { NetInputPlayer player = netPlayerList[index]; player.SetActive(true, remoteIp); player.Send(NetInputData.Create_Command_ResetPlayerIndex(index)); //设定游戏设备信息 player.Send(NetInputData.Create_Command_SetGameDeviceInfo((int)gameDeviceSelect, (int)gameDeviceFunction)); }