/// <summary> /// Sends the specified string to all clients, excluding the one specified in exclude, using the specified MemoryStream. /// </summary> /// <param name="data">The MemoryStream containing data to send</param> /// <param name="exclude">Null if all clients should get this data</param> private void propogate(MemoryStream stream, TcpClient exclude) { foreach (Player p in clientList.Values) { if (p.client != exclude) CSCommon.sendData(p.client, stream); } }
bool ChangeEntityWorkers() { if (m_EntityType != m_Entity.m_Type) { m_EntityType = m_Entity.m_Type; return(true); } else { CSCommon com = m_Entity as CSCommon; if (com == null) { return(false); } if (com.WorkerMaxCount != mPersonnelList.Count) { return(true); } for (int i = 0; i < com.WorkerMaxCount; i++) { if (com.Worker(i) != mPersonnelList[i]) { return(true); } } } return(false); }
void UpdateState() { m_NotHaveAssemblyCount = 0; m_AssemblyLevelInsufficientCount = 0; m_NotHaveElectricityCount = 0; for (int i = 0; i < m_EntityList.Count; i++) { CSCommon common = m_EntityList[i] as CSCommon; if (common != null && common.Assembly == null) { m_NotHaveAssemblyCount++; //lz-2016.06.08 蒲及告诉我如果没有核心,但是在核心的范围内,就说明核心等级不足 if (null != CSUI_MainWndCtrl.Instance.Creator && null != CSUI_MainWndCtrl.Instance.Creator.Assembly && CSUI_MainWndCtrl.Instance.Creator.Assembly.InRange(m_EntityList[i].Position)) { m_AssemblyLevelInsufficientCount++; } } if (common != null && common.Assembly != null && !m_EntityList[i].IsRunning) { m_NotHaveElectricityCount++; } } m_NotHaveAssembly = m_NotHaveAssemblyCount > 0; m_AssemblyLevelInsufficient = m_AssemblyLevelInsufficientCount > 0; m_NotHaveElectricity = m_NotHaveElectricityCount > 0; mSpDisabled.enabled = m_NotHaveElectricity; mSpDumped.enabled = m_NotHaveAssembly; mForGroundSp.spriteName = m_NotHaveElectricity ? fgSprNameRed : fgSprNameWhite; mBakgroundSp.spriteName = m_NotHaveElectricity ? bgSprNameRed : bgSprNameWhite; }
/// <summary> /// Sends a chat message /// </summary> /// <param name="tag">The tag of the player sending a message. Can be null</param> /// <param name="message">The message</param> /// <param name="type">The message type</param> private void sendChatMessage(String tag, String message, MessageType type) { if (tag != null) message = clientList[tag].name + ": " + message; propogate(CSCommon.buildCMDString(CSCommon.cmd_chat, (byte)type, message), (tag != null) ? clientList[tag].client : null); output(LoggingLevels.chat, message); }
/// <summary> /// Sets the work room. /// </summary> /// <param name="workRoom">Work room. : NULL means clear the work room, /// note thant it will remeber by brain.</param> private void SetWorkRoom(CSCommon workRoom) { if (m_WorkRoom != workRoom) { if (m_WorkRoom != null) { m_WorkRoom.RemoveWorker(this); if (workRoom == null) { WorkMachine = null; } else { PersonnelSpace ps = workRoom.FindEmptySpace(this); if (ps != null) { ps.m_Person = this; WorkMachine = ps.WorkMachine; HospitalMachine = ps.HospitalMachine; TrainerMachine = ps.TrainerMachine; } workRoom.AddWorker(this); } } else { PersonnelSpace ps = workRoom.FindEmptySpace(this); if (ps != null) { ps.m_Person = this; WorkMachine = ps.WorkMachine; HospitalMachine = ps.HospitalMachine; TrainerMachine = ps.TrainerMachine; } workRoom.AddWorker(this); } m_WorkRoom = workRoom; if (workRoom != null) { Data.m_WorkRoomID = workRoom.ID; } else { Data.m_WorkRoomID = -1; } if (m_NpcCmpt != null) { m_NpcCmpt.WorkEntity = m_WorkRoom; m_NpcCmpt.Work = WorkMachine; m_NpcCmpt.Cure = HospitalMachine; m_NpcCmpt.Trainner = TrainerMachine; } } }
private void sendCriticalMessage() { if (String.IsNullOrEmpty(serverMessage)) return; lock (serverMessage) { foreach (Player p in clientList.Values) CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_chat, (byte)MessageType.critical, serverMessage)); serverMessage = ""; } }
void OnDisbandAllBtn() { CSCommon csc = m_Entity as CSCommon; if (csc != null) { csc.ClearWorkers(); // CSUI_Main.ShowStatusBar("Disband all workers who work for this machine"); } }
void OnAutoSettleBtn() { CSCommon csc = m_Entity as CSCommon; if (csc != null) { csc.AutoSettleWorkers(); // CSUI_Main.ShowStatusBar("Auto settle some workers in this machine!"); } }
/// <summary> /// This method will periodically tick and check if a client has sent data. /// It will run on its own thread and is the main operation of the server. /// </summary> private void startMonitoringForData() { const int waitTime = 10; while (true) { try { if (returns.Count > 0) enterPendingPlayers(); //pause(); lock (lockObject) { modifiedClientList = false; foreach (String s in clientList.Keys) { if (!CSCommon.isLiveConnection(clientList[s].client)) { String name = clientList[s].name; removeFromGame(s, false, DisconnectMethod.midGame); sendMessage(name + " has been unexpectedly disconnected.", null); } else performCMDRCV(s, clientList[s].client); //In case player wanted to be disconnected if (modifiedClientList) break; } //for } //lock if (!modifiedClientList) Thread.Sleep(waitTime); if (isGameEnd()) { output(LoggingLevels.debug, "Doing game ended routine"); if (!forceGameEnd) //don't give points if team death player disconnected allocatePoints(); else { if (reason == null) sendMessage("The game has ended.", null); else sendMessage("The game has ended because " + reason, null); propogate(CSCommon.buildCMDString(CSCommon.cmd_gameEnded), null); while (clientList.Count != 0) { foreach (String s in clientList.Keys) { removeFromGame(s, true, DisconnectMethod.midGame); //remove clients one by one break; //release enumerator } //foreach } //while } //if forced to end the game by server-side event. if (gameFinished != null) gameFinished(this); return; } //if game ended sendCriticalMessage(); } catch (Exception e) { output(LoggingLevels.error, e.Message + e.StackTrace); setForceGameEnd("there was a problem with the game."); } } //while }
/// <summary> /// Creates a bot. /// </summary> /// <param name="creator">The tag of the player that will hold the bot's data initially.</param> /// <param name="objectType">The type of the bot.</param> private void createBot(String creator, ObjectType objectType) { String id = getBotID(); String botName = "Bot " + id; String botId = "B-" + id; CSCommon.sendData(clientList[creator].client, CSCommon.buildCMDString(CSCommon.cmd_createBot, botId, botName, (byte)objectType)); //Other players will just see another spawn. propogate(CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, botId, botName, (byte)objectType, (short)0), clientList[creator].client); if (objectType == ObjectType.aircraft) sendMessage(botName + " has been created.", null); bots.Add(new BotInfo(creator, botId, botName, objectType)); bots.Sort(); }
public void SetEntity(CSCommon entity) { if (entity != null && entity.m_Type != CSConst.etEnhance && entity.m_Type != CSConst.etRepair && entity.m_Type != CSConst.etRecyle) { Debug.Log("The giving Entity is not allowed!"); return; } m_Type = entity.m_Type; m_Entity = entity; CSUI_MainWndCtrl.Instance.mSelectedEnntity = m_Entity; if (m_Type == CSConst.etEnhance) { CSEnhance cse = m_Entity as CSEnhance; if (cse.m_Item == null) { SetItem(null); } else { SetItem(cse.m_Item.itemObj); } } else if (m_Type == CSConst.etRepair) { CSRepair csr = m_Entity as CSRepair; if (csr.m_Item == null) { SetItem(null); } else { SetItem(csr.m_Item.itemObj); } } else if (m_Type == CSConst.etRecyle) { CSRecycle csr = m_Entity as CSRecycle; if (csr.m_Item == null) { SetItem(null); } else { SetItem(csr.m_Item.itemObj); } } }
//lz-2016.06.08 获取没有核心的所有名字 public List <string> GetNamesByNotHaveAssembly() { List <string> names = new List <string>(); for (int i = 0; i < m_EntityList.Count; i++) { CSCommon common = m_EntityList[i] as CSCommon; if (common != null && common.Assembly == null) { names.Add(CSUtils.GetEntityName(m_EntityList[i].m_Type)); } } return(names); }
public CSEntity _createEntity(CSEntityAttr attr) { // Assembly if (attr.m_Type == CSConst.etAssembly) { m_Assembly = new CSAssembly(); m_Assembly.m_Info = CSInfoMgr.m_AssemblyInfo; m_Assembly.ID = attr.m_InstanceId; m_Assembly.gameLogic = attr.m_LogicObj; m_Assembly.gameObject = attr.m_Obj; m_Assembly.m_Creator = this; //multiMode only m_Assembly._ColonyObj = attr.m_ColonyBase; m_Assembly.CreateData(); m_Assembly.Position = attr.m_Pos; m_Assembly.ItemID = attr.m_protoId; m_Assembly.Bound = attr.m_Bound; m_Assembly.Data.m_Alive = true; m_Assembly.InitErodeMap(attr.m_Pos, m_Assembly.Radius); m_Timer.Tick = m_Assembly.Data.m_TimeTicks; return(m_Assembly); } else { CSCommon csc = _CreateCommon(attr.m_Type); csc.ID = attr.m_InstanceId; //multiMode only csc._ColonyObj = attr.m_ColonyBase; csc.CreateData(); csc.Position = attr.m_Pos; csc.m_Power = attr.m_Power; csc.gameLogic = attr.m_LogicObj; csc.gameObject = attr.m_Obj; csc.ItemID = attr.m_protoId; csc.Bound = attr.m_Bound; csc.BaseData.m_Alive = true; m_CommonEntities.Add(csc.ID, csc); return(csc); } }
public void TrySetWorkRoom(CSCommon w) { if (WorkRoom == w) { return; } if (PeGameMgr.IsMulti) { ((AiAdNpcNetwork)NetworkInterface.Get(ID)).RPCServer(EPacketType.PT_CL_CLN_SetWorkRoomID, w.ID); } else { WorkRoom = w; } }
//lz-2016.06.08 获取没有电的所有名字 public List <string> GetNamesByNotHaveElectricity() { List <string> names = new List <string>(); for (int i = 0; i < m_EntityList.Count; i++) { CSCommon common = m_EntityList[i] as CSCommon; //lz-2016.08.21 有核心没有运行说明没有电 if (common != null && common.Assembly != null && !m_EntityList[i].IsRunning) { names.Add(CSUtils.GetEntityName(m_EntityList[i].m_Type)); } } return(names); }
/// <summary> /// Pushes the bot to a new player, in the event the previous host was disconnected. The bots list will always be modified after this method runs. Call this method after removing the player. /// </summary> /// <param name="index">The position in bots to remove.</param> private void pushBot(int index) { String botID = bots[index].id; String botName = bots[index].name; ObjectType objectType = bots[index].objectType; if (clientList.Count == 0) { bots[index].creator = null; return; } String[] ids = clientList.Keys.ToArray(); Random r = new Random(); String pid = null; //ID of new host player for bot CSCommon.sendData(clientList[pid = ids[r.Next(0, ids.Length)]].client, CSCommon.buildCMDString(CSCommon.cmd_createBot, botID, botName, (byte)objectType)); bots[index].creator = pid; }
//lz-2016.06.08 获取核心等级不足的所有名字 public List <string> GetNamesByAssemblyLevelInsufficient() { List <string> names = new List <string>(); for (int i = 0; i < m_EntityList.Count; i++) { CSCommon common = m_EntityList[i] as CSCommon; //lz-2016.08.21 在核心范围内,但是没有核心,说明核心等级不足 if (common != null && common.Assembly == null && null != CSUI_MainWndCtrl.Instance.Creator && null != CSUI_MainWndCtrl.Instance.Creator.Assembly && CSUI_MainWndCtrl.Instance.Creator.Assembly.InRange(m_EntityList[i].Position)) { names.Add(CSUtils.GetEntityName(m_EntityList[i].m_Type)); } } return(names); }
public void ShowWorkSpaceEffect() { if (m_LocEffectPrefab == null) { return; } if (m_Entity != null) { CSCommon csc = m_Entity as CSCommon; if (csc.WorkPoints == null) { return; } for (int i = 0; i < csc.WorkPoints.works.Length; i++) { if (csc.WorkPoints.works[i] != null && !m_LocEffects.ContainsKey(i)) { LocateCubeEffectHanlder lce = Instantiate(m_LocEffectPrefab) as LocateCubeEffectHanlder; lce.transform.parent = this.transform; Vector3 pos = csc.WorkPoints.works[i].transform.position; pos.y += (lce.m_CubeLen * 0.5f * lce.m_MaxHeightScale) + 0.05f; lce.transform.position = pos; lce.transform.localRotation = Quaternion.identity; m_LocEffects.Add(i, lce); } } } else { for (int i = 0; i < m_WorkTrans.Length; i++) { if (!m_LocEffects.ContainsKey(i)) { LocateCubeEffectHanlder lce = Instantiate(m_LocEffectPrefab) as LocateCubeEffectHanlder; lce.transform.parent = this.transform; Vector3 pos = m_WorkTrans[i].position; pos.y += (lce.m_CubeLen * 0.5f * lce.m_MaxHeightScale) + 0.05f; lce.transform.position = pos; lce.transform.localRotation = Quaternion.identity; m_LocEffects.Add(i, lce); } } } }
public void DetachCommonEntity(CSCommon csc) { csc.Assembly = null; // m_BelongObjectsMap[(CSConst.ObjectType) csc.m_Type].Remove(csc); RemoveBelongBuilding((CSConst.ObjectType)csc.m_Type, csc); CSElectric cse = csc as CSElectric; if (cse != null) { if (cse.m_PowerPlant != null) { cse.m_PowerPlant.DetachElectric(cse); } } csc.ChangeState(); }
public void CreateData(CSPersonnelData data) { bool isNew = m_Creator.m_DataInst.AddData(data); m_Data = data; if (isNew && (!PeGameMgr.IsMulti)) { } else { Dwellings = m_Creator.GetCommonEntity(m_Data.m_DwellingsID) as CSDwellings; if (Dwellings != null) { Dwellings.AddNpcs(this); } CSCommon workRoom = m_Creator.GetCommonEntity(m_Data.m_WorkRoomID); //if (workRoom != null && workRoom.AddWorker(this)) //m_BrainMemory.Add(workRoom); if (workRoom != null) { WorkRoom = workRoom; } //_createGuardTriggerGo (); //m_GuardTrigger.Pos = Data.m_GuardPos; if (processingIndex >= 0) { if (m_ProcessingIndexInitListenner != null) { m_ProcessingIndexInitListenner(this); } } //if (m_Dwellings != null && m_Dwellings.Assembly != null) //{ // if ( !m_Dwellings.Assembly.InRange(m_Pos) ) // _state = CSConst.pstUnknown; //} } //--to do: wait //m_Skill.RegisterListener(OnNPCEventTrigger); }
/// <summary> /// Removes a player from this game. if disconnectFromServer == true, we'll assume player /// either did hard shutdown, or was dropped forcibly by the game because their connection timed out. /// In this case, we send cmd_forceDisconnect command to each client so they can get rid of that player's object. Otherwise, we'll just put them back in the hangar. /// </summary> /// <param name="tag">The tag of the player to remove.</param> /// <param name="keepOnServer">If true, this player will not be dropped from the server.</param> /// <param name="d">The method by which this player is being disconnected. If the player was disconnected because they lost, /// this flag should be set to gameEnd. Otherwise, if the player hit escape or was dropped, this flag should be set to midGame.</param> private void removeFromGame(String tag, bool keepOnServer, DisconnectMethod d) { if (clientList[tag].host) //If this is the game host, forceGameEnd = true; //If they drop or disconnect, end the game. Server.returnFromGame(tag, clientList[tag], keepOnServer); clientList.Remove(tag); //In case this is a case where the client was disconnected without an in-game event, //IE: a connection drop, tell all clients that this object has disconnected so they can //clean it up. propogate(CSCommon.buildCMDString(CSCommon.cmd_forceDisconnect, tag), null); if (clientList.Count == 0) canEvaluateGameEnd = true; modifiedClientList = true; if (type == GameType.freeForAll) clearBotsFromPlayer(tag); //now game is unbalanced, so call it quit since players may cheat this way, //by starting a team death, disconnecting, and the other team gets all the points. //Or if there's a death match and only one player remains after this disconnect, just end the game since one player in a deth match is pointless! if (type == GameType.teamDeath && d == DisconnectMethod.midGame || type == GameType.oneOnOne && clientList.Count == 1) forceGameEnd = true; }
public int AttachCommonEntity(CSCommon csc) { if (csc.Assembly == this) { return(CSConst.rrtUnkown); } if (!InRange(csc.Position)) { return(CSConst.rrtOutOfRadius); } CSConst.ObjectType type = (CSConst.ObjectType)csc.m_Type; if (IsOutOfLimit(type)) { return(CSConst.rrtOutOfRange); } // m_BelongObjectsMap[(CSConst.ObjectType) csc.m_Type].Add(csc); AddBelongBuilding((CSConst.ObjectType)csc.m_Type, csc); csc.Assembly = this; CSElectric cse = csc as CSElectric; if (cse != null) { foreach (CSCommon power in AllPowerPlants) { CSPowerPlant cspp = power as CSPowerPlant; cspp.AttachElectric(cse); if (cse.IsRunning) { break; } } } csc.ChangeState(); return(CSConst.rrtSucceed); }
void OnEntityEventListener(int event_id, CSEntity entity, object arg) { CSCommon csc = entity as CSCommon; if (csc == null) { return; } if (event_id == CSConst.eetDestroy) { csc.RemoveEventListener(OnEntityEventListener); CSUI_EntityState es = m_EntitesState.Find(item0 => item0.m_RefCommon == csc); if (es != null) { GameObject.Destroy(es.gameObject); m_EntitesState.Remove(es); m_EntityRootUI.repositionNow = true; } } }
// void OnAssemblyEventHandler(int event_type, CSEntity entity, object arg) { if (event_type == CSConst.eetAssembly_AddBuilding) { CSCommon common = arg as CSCommon; if (common == null) { Debug.LogError("The argument is error"); return; } // if (m_WorkMode == CSConst.pwtPatrol) // { // common.AddSoldier(this); // } // else if (m_WorkMode == CSConst.pwtGuard) // { // if ( CSUtils.SphereContainsAndIntersectBound(m_GuardTrigger.Pos, m_GuardTrigger.Radius, entity.Bound)) // common.AddSoldier(this); // } } }
void RefalshWorkersGrid() { CSCommon com = m_Entity as CSCommon; if (com == null) { return; } if (com.WorkerCount > mUIWokerList.Count) { AddCSUI_WorkeItem(com.WorkerCount - mUIWokerList.Count); } int j = 0; for (int i = 0; i < com.WorkerMaxCount; i++) { if (com.Worker(i) != null) { mUIWokerList[j].SetWorker(com.Worker(i)); mUIWokerList[j].gameObject.SetActive(true); j++; } } for (int i = j; i < mUIWokerList.Count; i++) { mUIWokerList[i].gameObject.SetActive(false); } mPersonnelList.Clear(); for (int i = 0; i < com.WorkerMaxCount; i++) { mPersonnelList.Add(com.Worker(i)); } mWorkerGrid.repositionNow = true; }
/// <summary> /// Sends a private message. /// </summary> /// <param name="target">The recipient of the message</param> /// <param name="message">The message to send</param> private void sendPrivateChatMessage(String target, String message) { Player p = getPlayerByID(target); if (p != null) CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_chat, (byte)MessageType.privateMessage, message)); }
public void RemoveBelongBuilding(CSConst.ObjectType type, CSCommon building) { m_BelongObjectsMap[type].Remove(building); ExcuteEvent(CSConst.eetAssembly_RemoveBuilding, building); }
/// <summary> /// This method will add a new player to this game. /// </summary> /// <param name="tag">The server tag of the player being added</param> /// <param name="p">The Player object representing the connection.</param> private bool add(String tag, Player p) { try { //pauseProcessing(); output("Adding player " + tag + "..."); lock (lockObject) { if (clientList.Count == 0 && type != GameType.freeForAll) //This is first player being added, so this is the host. p.host = true; //Create local player. if (p.entryMode != 1) { int maxWeight = 0; CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_position, next++, (short)0)); CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_requestCreate, p.name, maxWeight)); //Give this player's info to all players. output("Propogating connection...", true); if (type != GameType.teamDeath) { propogate(CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, tag, p.name, (byte)ObjectType.aircraft, (short)0), p.client); } else { //if team death propogate(CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, tag, p.name, (byte)ObjectType.aircraft, (int)p.team, (short)0), p.client); } } //if entryMode != 1 //Give this player info about all other players. output("Sending info about other clients to this client...", true); foreach (Player player in clientList.Values) { if (player.entryMode == 1) //spectator continue; if (type != GameType.teamDeath) { CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, player.tag, player.name, (byte)ObjectType.aircraft, (short)0)); } else { //if team death CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, player.tag, player.name, (byte)ObjectType.aircraft, (int)player.team, (short)0)); } } //foreach connected player foreach (BotInfo info in bots) { if (info.creator == null) { info.creator = tag; CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_createBot, info.id, info.name, (byte)info.objectType)); CSCommon.sendData(p.client, new MemoryStream(info.data)); output("Created bot " + info.id, true); } else CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_distributeServerTag, info.id, info.name, (byte)info.objectType, (short)0)); } if (type == GameType.freeForAll) { output("FFA, Starting local player...", true); CSCommon.sendData(p.client, CSCommon.buildCMDString(CSCommon.cmd_startGame)); } //if FFA clientList[tag] = p; if (type == GameType.teamDeath) incrementTeam(tag, p.team); String entMessage = "."; if (type == GameType.teamDeath) entMessage = " for the " + p.team + " team"; sendMessage(clientList[tag].name + String.Format(" has joined this game{0}", (p.entryMode == 1) ? " as a spectator" : entMessage), p.client); } //lock if (type != GameType.freeForAll && !canEvaluateGameEnd && (type == GameType.teamDeath && getNumberOfTeams() >= 2 || type != GameType.teamDeath)) canEvaluateGameEnd = true; //resumeProcessing(); return true; } catch (Exception e) { output(e.Message + Environment.NewLine + e.StackTrace); } return false; }
/// <summary> /// Sends a server message to all clients. To include everyone, send NULL to the exclude parameter. /// </summary> /// <param name="message">The message to send.</param> /// <param name="exclude">The client to exclude.</param> private void sendMessage(String message, TcpClient exclude) { propogate(CSCommon.buildCMDString(CSCommon.cmd_serverMessage, message), exclude); output(message); }
/// <summary> /// gets data from the TCPClient passed and does a command based on the given data. This command could result in information being passed to other TCPClient objects, for instance if we've recieved information about an aircraft's state that needs to be propogated. /// </summary> /// <param name="tag">The GUID of the player to perform commands on</param> /// <param name="client">The player's TcpClient object</param> private void performCMDRCV(String tag, TcpClient client) { if (!CSCommon.isLiveConnection(client)) return; MemoryStream stream = CSCommon.getData(client); if (stream == null) return; BinaryReader rcvData = new BinaryReader(stream); //rcvData is the list of serverCommands. sbyte c = 0; long start = 0L; byte command = 0; try { while (rcvData.BaseStream.Length > rcvData.BaseStream.Position) { start = rcvData.BaseStream.Position; c = rcvData.ReadSByte(); if (c > 4) return; if (c == 1) { command = rcvData.ReadByte(); switch (command) { case CSCommon.cmd_test: int testAmount = recordWin("6SRKJ695G", "ABCDEFGHI"); CSCommon.sendData(client, CSCommon.buildCMDString(CSCommon.cmd_newval, testAmount)); break; case CSCommon.cmd_createBot: //The player who creates the bot will spawn a thread to control them. createBot(tag, ObjectType.aircraft); break; case CSCommon.cmd_removeBot: String rBotId = removeBot(0); if (rBotId == null) break; sendMessage(rBotId + " has been dropped from the server", null); propogate(CSCommon.buildCMDString(CSCommon.cmd_forceDisconnect, rBotId), null); break; case CSCommon.cmd_whois: using (BinaryWriter whoWriter = new BinaryWriter(new MemoryStream())) { whoWriter.Write((short)clientList.Count); foreach (Player p in clientList.Values) { whoWriter.Write(p.tag); whoWriter.Write(p.name + ((p.admin) ? " (GM)" : "")); } CSCommon.sendResponse(client, whoWriter); } //using break; case CSCommon.cmd_requestStartGame: if (type == GameType.oneOnOne && clientList.Count == 2) gameStarted = true; if (type == GameType.teamDeath) { if (getNumberOfTeams() >= 2) gameStarted = true; } //if team death CSCommon.sendResponse(client, gameStarted); if (gameStarted) { propogate(CSCommon.buildCMDString(CSCommon.cmd_startGame), client); } break; case CSCommon.cmd_updatePoints: Player winner = getPlayerByID(rcvData.ReadString()); if (winner == null) //winner logged off; kill doesn't count! break; //The client sending this command is the loser. int amount = recordWin(winner.tag, tag); CSCommon.sendData(winner.client, CSCommon.buildCMDString(CSCommon.cmd_newval, amount)); break; case CSCommon.cmd_startGame: //Send cmd_startGame to all clients so they can //signal start locally. propogate(CSCommon.buildCMDString(CSCommon.cmd_startGame), client); break; case CSCommon.cmd_chat: bool isPrivate = rcvData.ReadBoolean(); String chatMsg = null; if (isPrivate) { String recipient = rcvData.ReadString(); chatMsg = clientList[tag].name + " (private): " + rcvData.ReadString(); sendPrivateChatMessage(recipient, chatMsg); } else { chatMsg = rcvData.ReadString(); sendChatMessage(tag, chatMsg, MessageType.normal); } break; case CSCommon.cmd_serverMessage: sendMessage(rcvData.ReadString(), client); break; case CSCommon.cmd_disconnectMe: String name = clientList[tag].name; removeFromGame(tag, true, DisconnectMethod.midGame); sendMessage(name + " has left the game.", null); return; //no need to process things further. case CSCommon.cmd_deleteFromGame: //silent exit removeFromGame(tag, true, DisconnectMethod.gameEnded); //delete will only be sent on successful game end return; //no need to process data further. } //switch } //if explicit command else { byte[] buffer = new byte[rcvData.ReadInt32()]; string id = rcvData.ReadString(); bool updateBot = false; int botIndex = 0; if (c == 3) { if ((botIndex = getBot(id)) > -1) { rcvData.ReadInt16(); //passed numArgs while (rcvData.ReadSByte() != 1) ; if (rcvData.ReadInt32() > 0) updateBot = true; else removeBot(botIndex); } //if bot exists } //if this is a bot update rcvData.BaseStream.Position = start; rcvData.BaseStream.Read(buffer, 0, buffer.Length); if (updateBot) bots[botIndex].data = buffer; propogate(buffer, client); } //if something else besides cmd_command. } //foreach serverCommand } catch (Exception e) { output("Error while reading data from " + tag + ". Char = " + c + Environment.NewLine + "Last command: " + command + Environment.NewLine + "Stack trace: " + e.Message + e.StackTrace); } //catch }