/* * protected override void DispatchMapListClearResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 1) { * if (this.MapListCleared != null) { * FrostbiteConnection.RaiseEvent(this.MapListCleared.GetInvocationList(), this); * } * } * } */ protected override void DispatchMapListAppendResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 4) { MaplistEntry mapEntry = null; int rounds = 0; int index = -1; if (int.TryParse(cpRequestPacket.Words[3], out rounds) == true) { mapEntry = new MaplistEntry(cpRequestPacket.Words[2], cpRequestPacket.Words[1], rounds); } if (cpRequestPacket.Words.Count >= 5 && int.TryParse(cpRequestPacket.Words[4], out index) == true) { mapEntry = new MaplistEntry(cpRequestPacket.Words[2], cpRequestPacket.Words[1], rounds, index); } if (this.MapListMapAppended != null) { if (index == -1) { FrostbiteConnection.RaiseEvent(this.MapListMapAppended.GetInvocationList(), this, mapEntry); } else { FrostbiteConnection.RaiseEvent(this.MapListMapInserted.GetInvocationList(), this, mapEntry); } } } }
protected override void DispatchPlayerOnSpawnRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 9) { if (this.PlayerSpawned != null) { FrostbiteConnection.RaiseEvent(this.PlayerSpawned.GetInvocationList(), this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words.GetRange(3, 3), cpRequestPacket.Words.GetRange(6, 3)); // new Inventory(cpRequestPacket.Words[3], cpRequestPacket.Words[4], cpRequestPacket.Words[5], cpRequestPacket.Words[6], cpRequestPacket.Words[7], cpRequestPacket.Words[8])); } } }
public MoHClient(FrostbiteConnection connection) : base(connection) { ResponseDelegates.Add("vars.clanTeams", DispatchVarsClanTeamsResponse); ResponseDelegates.Add("vars.noCrosshairs", DispatchVarsNoCrosshairsResponse); ResponseDelegates.Add("vars.realisticHealth", DispatchVarsRealisticHealthResponse); ResponseDelegates.Add("vars.noUnlocks", DispatchVarsNoUnlocksResponse); ResponseDelegates.Add("vars.skillLimit", DispatchVarsSkillLimitResponse); ResponseDelegates.Add("vars.noAmmoPickups", DispatchVarsNoAmmoPickupsResponse); ResponseDelegates.Add("vars.tdmScoreCounterMaxScore", DispatchVarsTdmScoreCounterMaxScoreResponse); // Preround vars ResponseDelegates.Add("vars.preRoundLimit", DispatchVarsPreRoundLimitResponse); ResponseDelegates.Add("admin.roundStartTimerEnabled", DispatchAdminRoundStartTimerEnabledResponse); ResponseDelegates.Add("vars.roundStartTimerDelay", DispatchVarsRoundStartTimerDelayResponse); ResponseDelegates.Add("vars.roundStartTimerPlayersLimit", DispatchVarsRoundStartTimerPlayersLimitResponse); // New map functions? ResponseDelegates.Add("admin.stopPreRound", DispatchAdminStopPreRoundResponse); // Note: These delegates point to methods in FrostbiteClient. ResponseDelegates.Add("reservedSpectateSlots.configFile", DispatchReservedSlotsConfigFileResponse); ResponseDelegates.Add("reservedSpectateSlots.load", DispatchReservedSlotsLoadResponse); ResponseDelegates.Add("reservedSpectateSlots.save", DispatchReservedSlotsSaveResponse); ResponseDelegates.Add("reservedSpectateSlots.addPlayer", DispatchReservedSlotsAddPlayerResponse); ResponseDelegates.Add("reservedSpectateSlots.removePlayer", DispatchReservedSlotsRemovePlayerResponse); ResponseDelegates.Add("reservedSpectateSlots.clear", DispatchReservedSlotsClearResponse); ResponseDelegates.Add("reservedSpectateSlots.list", DispatchReservedSlotsListResponse); GetPacketsPattern = new Regex(GetPacketsPattern + "|^reservedSpectateSlots.list|^admin.roundStartTimerEnabled$|^admin.tdmScoreCounterMaxScore$", RegexOptions.Compiled); }
protected override void DispatchServerInfoResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (this.ServerInfo != null) { CServerInfo newServerInfo = new CServerInfo( new List <string>() { "ServerName", "PlayerCount", "MaxPlayerCount", "GameMode", "Map", "CurrentRound", "TotalRounds", "TeamScores", "ConnectionState", "Ranked", "PunkBuster", "Passworded", "ServerUptime", "RoundTime", "GameMod", // Note: if another variable is affixed to both games this method "Mappack", // will need to be split into MoHClient and BFBC2Client. "ExternalGameIpandPort", // "PunkBusterVersion", //"JoinQueueEnabled", //"ServerRegion" }, cpRecievedPacket.Words.GetRange(1, cpRecievedPacket.Words.Count - 1) ); FrostbiteConnection.RaiseEvent(this.ServerInfo.GetInvocationList(), this, newServerInfo); } }
public void AttemptConnection() { try { lock (this.QueueUnqueuePacketLock) { this.QueuedPackets.Clear(); this.OutgoingPackets.Clear(); } this.SequenceNumber = 0; this.Client = new TcpClient(); this.Client.NoDelay = true; this.Client.BeginConnect(this.Hostname, this.Port, this.ConnectedCallback, this); if (this.ConnectAttempt != null) { FrostbiteConnection.RaiseEvent(this.ConnectAttempt.GetInvocationList(), this); } } catch (SocketException se) { this.Shutdown(se); } catch (Exception e) { this.Shutdown(e); } }
private void ConnectedCallback(IAsyncResult ar) { try { this.Client.EndConnect(ar); this.Client.NoDelay = true; if (this.ConnectSuccess != null) { FrostbiteConnection.RaiseEvent(this.ConnectSuccess.GetInvocationList(), this); } this.NetworkStream = this.Client.GetStream(); this.NetworkStream.BeginRead(this.ReceivedBuffer, 0, this.ReceivedBuffer.Length, this.ReceiveCallback, this); if (this.ConnectionReady != null) { FrostbiteConnection.RaiseEvent(this.ConnectionReady.GetInvocationList(), this); } } catch (SocketException se) { this.Shutdown(se); } catch (Exception e) { this.Shutdown(e); } }
private void ShutdownConnection() { lock (new object()) { if (this.m_tcpClient != null) { try { this.ClearConnection(); if (this.m_nwsStream != null) { this.m_nwsStream.Close(); this.m_nwsStream.Dispose(); this.m_nwsStream = null; } if (this.m_tcpClient != null) { this.m_tcpClient.Close(); this.m_tcpClient = null; } } catch (SocketException se) { if (this.SocketException != null) { FrostbiteConnection.RaiseEvent(this.SocketException.GetInvocationList(), this, se); //this.SocketException(se); } } catch (Exception) { } } } }
public BFBC2Client(FrostbiteConnection connection) : base(connection) { #region Map list functions ResponseDelegates.Add("admin.getPlaylist", DispatchAdminGetPlaylistResponse); ResponseDelegates.Add("admin.setPlaylist", DispatchAdminSetPlaylistResponse); // Note: These delegates point to methods in FrostbiteClient. ResponseDelegates.Add("admin.runNextLevel", DispatchAdminRunNextRoundResponse); ResponseDelegates.Add("admin.currentLevel", DispatchAdminCurrentLevelResponse); #endregion //this.m_responseDelegates.Add("vars.rankLimit", this.DispatchVarsRankLimitResponse); // Note: These delegates point to methods in FrostbiteClient. ResponseDelegates.Add("reservedSlots.configFile", DispatchReservedSlotsConfigFileResponse); ResponseDelegates.Add("reservedSlots.load", DispatchReservedSlotsLoadResponse); ResponseDelegates.Add("reservedSlots.save", DispatchReservedSlotsSaveResponse); ResponseDelegates.Add("reservedSlots.addPlayer", DispatchReservedSlotsAddPlayerResponse); ResponseDelegates.Add("reservedSlots.removePlayer", DispatchReservedSlotsRemovePlayerResponse); ResponseDelegates.Add("reservedSlots.clear", DispatchReservedSlotsClearResponse); ResponseDelegates.Add("reservedSlots.list", DispatchReservedSlotsListResponse); GetPacketsPattern = new Regex(GetPacketsPattern + "|^admin.getPlaylist|^reservedSlots.list", RegexOptions.Compiled); }
public BFBC2Client(FrostbiteConnection connection) : base(connection) { #region Map list functions this.m_responseDelegates.Add("admin.getPlaylist", this.DispatchAdminGetPlaylistResponse); this.m_responseDelegates.Add("admin.setPlaylist", this.DispatchAdminSetPlaylistResponse); // Note: These delegates point to methods in FrostbiteClient. this.m_responseDelegates.Add("admin.runNextLevel", this.DispatchAdminRunNextRoundResponse); this.m_responseDelegates.Add("admin.currentLevel", this.DispatchAdminCurrentLevelResponse); #endregion //this.m_responseDelegates.Add("vars.rankLimit", this.DispatchVarsRankLimitResponse); // Note: These delegates point to methods in FrostbiteClient. this.m_responseDelegates.Add("reservedSlots.configFile", this.DispatchReservedSlotsConfigFileResponse); this.m_responseDelegates.Add("reservedSlots.load", this.DispatchReservedSlotsLoadResponse); this.m_responseDelegates.Add("reservedSlots.save", this.DispatchReservedSlotsSaveResponse); this.m_responseDelegates.Add("reservedSlots.addPlayer", this.DispatchReservedSlotsAddPlayerResponse); this.m_responseDelegates.Add("reservedSlots.removePlayer", this.DispatchReservedSlotsRemovePlayerResponse); this.m_responseDelegates.Add("reservedSlots.clear", this.DispatchReservedSlotsClearResponse); this.m_responseDelegates.Add("reservedSlots.list", this.DispatchReservedSlotsListResponse); this.GetPacketsPattern = new Regex(this.GetPacketsPattern.ToString() + "|^admin.getPlaylist|^reservedSlots.list", RegexOptions.Compiled); }
public BFHLClient(FrostbiteConnection connection) : base(connection) { ResponseDelegates.Add("vars.roundStartReadyPlayersNeeded", DispatchVarsRoundStartReadyPlayersNeeded); // need to review vars.requireReadyPlayersToStart / vars.roundStartReadyPlayersPercent // vars.TeamSwitchCooldown // vars.teamSwitchingAllowed // vars.roundsToWin // undocumented vars.killFeed ResponseDelegates.Add("vars.hacker", DispatchVarsCommander); }
public void Shutdown(Exception e) { this.ShutdownConnection(); if (this.ConnectionFailure != null) { FrostbiteConnection.RaiseEvent(this.ConnectionFailure.GetInvocationList(), this, e); } }
public void Shutdown(SocketException se) { this.ShutdownConnection(); if (this.SocketException != null) { FrostbiteConnection.RaiseEvent(this.SocketException.GetInvocationList(), this, se); } }
private bool QueueUnqueuePacket(bool isSending, Packet packet, out Packet nextPacket) { nextPacket = null; bool response = false; lock (this.QueueUnqueuePacketLock) { if (isSending == true) { // If we have something that has been sent and is awaiting a response if (this.OutgoingPackets.Count > 0) { // Add the packet to our queue to be sent at a later time. this.QueuedPackets.Enqueue(packet); response = true; if (this.PacketQueued != null) { FrostbiteConnection.RaiseEvent(this.PacketQueued.GetInvocationList(), this, packet, Thread.CurrentThread.ManagedThreadId); } } // else - response = false } else { // Else it's being called from recv and cpPacket holds the processed RequestPacket. // Remove the packet if (packet != null) { if (this.OutgoingPackets.ContainsKey(packet.SequenceNumber) == true) { this.OutgoingPackets.Remove(packet.SequenceNumber); } } if (this.QueuedPackets.Count > 0) { nextPacket = this.QueuedPackets.Dequeue(); response = true; if (this.PacketDequeued != null) { FrostbiteConnection.RaiseEvent(this.PacketDequeued.GetInvocationList(), this, nextPacket, Thread.CurrentThread.ManagedThreadId); } } else { response = false; } } } return(response); }
//public override void DispatchResponsePacket(FrostbiteConnection connection, Packet cpRecievedPacket, Packet cpRequestPacket) { // base.DispatchResponsePacket(connection, cpRecievedPacket, cpRequestPacket); //} #endregion #region Overridden Request Handlers protected override void DispatchPlayerOnSpawnRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 7) { if (PlayerSpawned != null) { this.PlayerSpawned(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words.GetRange(3, 1), cpRequestPacket.Words.GetRange(4, 3)); // new Inventory(cpRequestPacket.Words[3], cpRequestPacket.Words[4], cpRequestPacket.Words[5], cpRequestPacket.Words[6], cpRequestPacket.Words[7], cpRequestPacket.Words[8])); } } }
protected virtual void DispatchAdminStopPreRoundResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { if (StopPreRound != null) { this.StopPreRound(this); } } }
protected virtual void DispatchAdminGetPlaylistResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1 && cpRecievedPacket.Words.Count >= 2) { if (this.PlaylistSet != null) { this.PlaylistSet(this, cpRecievedPacket.Words[1]); } } }
/* * protected override void DispatchAdminRestartRoundResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 1) { * if (this.RestartRound != null) { * FrostbiteConnection.RaiseEvent(this.RestartRound.GetInvocationList(), this); * } * } * } */ protected override void DispatchAdminSupportedMapsResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { /* * if (cpRequestPacket.Words.Count >= 2 && cpRecievedPacket.Words.Count > 1) { * if (this.SupportedMaps != null) { * FrostbiteConnection.RaiseEvent(this.SupportedMaps.GetInvocationList(), this, cpRequestPacket.Words[1], cpRecievedPacket.Words.GetRange(1, cpRecievedPacket.Words.Count - 1)); * } * } */ }
/* * protected override void DispatchAdminRunNextRoundResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 1) { * if (this.RunNextRound != null) { * FrostbiteConnection.RaiseEvent(this.RunNextRound.GetInvocationList(), this); * } * } * } */ protected override void DispatchAdminCurrentLevelResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1 && cpRecievedPacket.Words.Count >= 2) { if (this.CurrentLevel != null) { FrostbiteConnection.RaiseEvent(this.CurrentLevel.GetInvocationList(), this, cpRecievedPacket.Words[1]); } } }
protected virtual void DispatchAdminStopPreRoundResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { if (this.StopPreRound != null) { FrostbiteConnection.RaiseEvent(this.StopPreRound.GetInvocationList(), this); } } }
protected virtual void DispatchAdminSetPlaylistResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { if (this.PlaylistSet != null) { FrostbiteConnection.RaiseEvent(this.PlaylistSet.GetInvocationList(), this, cpRequestPacket.Words[1]); } } }
protected override void DispatchPlayerOnJoinRequest(FrostbiteConnection sender, Packet cpRequestPacket) { base.DispatchPlayerOnJoinRequest(sender, cpRequestPacket); if (cpRequestPacket.Words.Count >= 3) { if (this.PlayerAuthenticated != null) { FrostbiteConnection.RaiseEvent(this.PlayerAuthenticated.GetInvocationList(), this, cpRequestPacket.Words[1], cpRequestPacket.Words[2]); } } }
/* * protected override void DispatchAdminListPlayersResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 2) { * * cpRecievedPacket.Words.RemoveAt(0); * if (this.ListPlayers != null) { * * List<CPlayerInfo> lstPlayers = BF3PlayerInfo.GetPlayerList(cpRecievedPacket.Words); * CPlayerSubset cpsSubset = new CPlayerSubset(cpRequestPacket.Words.GetRange(1, cpRequestPacket.Words.Count - 1)); * * FrostbiteConnection.RaiseEvent(this.ListPlayers.GetInvocationList(), this, lstPlayers, cpsSubset); * } * } * } * * protected override void DispatchServerOnRoundOverPlayersRequest(FrostbiteConnection sender, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 2) { * * cpRequestPacket.Words.RemoveAt(0); * if (this.RoundOverPlayers != null) { * FrostbiteConnection.RaiseEvent(this.RoundOverPlayers.GetInvocationList(), this, BF3PlayerInfo.GetPlayerList(cpRequestPacket.Words)); * } * * } * } */ protected override void DispatchPlayerOnKillRequest(FrostbiteConnection sender, Packet cpRequestPacket) { bool blHeadshot = false; if (this.PlayerKilled != null) { if (bool.TryParse(cpRequestPacket.Words[4], out blHeadshot) == true) { FrostbiteConnection.RaiseEvent(this.PlayerKilled.GetInvocationList(), this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words[3], blHeadshot, new Point3D(0, 0, 0), new Point3D(0, 0, 0)); } } }
public void Shutdown() { if (this.m_tcpClient != null) { this.ShutdownConnection(); if (this.ConnectionClosed != null) { FrostbiteConnection.RaiseEvent(this.ConnectionClosed.GetInvocationList(), this); } } }
protected virtual void DispatchVarsRoundStartReadyPlayersNeeded(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { var handler = this.RoundStartReadyPlayersNeeded; if (handler != null) { if (cpRecievedPacket.Words.Count == 2) { handler(this, Convert.ToInt32(cpRecievedPacket.Words[1])); } else if (cpRequestPacket.Words.Count >= 2) { handler(this, Convert.ToInt32(cpRequestPacket.Words[1])); } } } }
/* * protected override void DispatchMapListNextLevelIndexResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 1) { * * int iMapIndex = 0; * if (this.MapListNextLevelIndex != null) { * if ((cpRequestPacket.Words.Count >= 2 && int.TryParse(cpRequestPacket.Words[1], out iMapIndex) == true) || cpRecievedPacket.Words.Count >= 2 && int.TryParse(cpRecievedPacket.Words[1], out iMapIndex) == true) { * FrostbiteConnection.RaiseEvent(this.MapListNextLevelIndex.GetInvocationList(), this, iMapIndex); * } * } * } * } * * protected override void DispatchMapListRemoveResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { * if (cpRequestPacket.Words.Count >= 2) { * * int iMapIndex = 0; * if (int.TryParse(cpRequestPacket.Words[1], out iMapIndex) == true) { * if (this.MapListMapRemoved != null) { * FrostbiteConnection.RaiseEvent(this.MapListMapRemoved.GetInvocationList(), this, iMapIndex); * } * } * } * } */ protected override void DispatchMapListInsertResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 4) { int iMapIndex = 0, iRounds = 0; if (int.TryParse(cpRequestPacket.Words[1], out iMapIndex) == true && int.TryParse(cpRequestPacket.Words[3], out iRounds) == true) { if (this.MapListMapInserted != null) { FrostbiteConnection.RaiseEvent(this.MapListMapInserted.GetInvocationList(), this, iMapIndex, cpRequestPacket.Words[2], iRounds); } } } }
protected override void DispatchPlayerOnSpawnRequest(FrostbiteConnection sender, Packet cpRequestPacket) { //if (cpRequestPacket.Words.Count >= 9) { if (this.PlayerSpawned != null) { FrostbiteConnection.RaiseEvent(this.PlayerSpawned.GetInvocationList(), this, cpRequestPacket.Words[1], "", new List <string>() { "", "", "" }, new List <string>() { "", "", "" }); // new Inventory(cpRequestPacket.Words[3], cpRequestPacket.Words[4], cpRequestPacket.Words[5], cpRequestPacket.Words[6], cpRequestPacket.Words[7], cpRequestPacket.Words[8])); } //} }
protected override void DispatchPlayerOnTeamChangeRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 3) { int iTeamID = 0; if (int.TryParse(cpRequestPacket.Words[2], out iTeamID) == true) { if (PlayerChangedTeam != null) { this.PlayerChangedTeam(this, cpRequestPacket.Words[1], iTeamID, 0); } } } }
// This can probably be removed once the onChat event is un-lamed. protected override void DispatchPlayerOnChatRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 3) { if (this.GlobalChat != null) { FrostbiteConnection.RaiseEvent(this.GlobalChat.GetInvocationList(), this, cpRequestPacket.Words[1], cpRequestPacket.Words[2]); } cpRequestPacket.Words.RemoveAt(0); if (this.Chat != null) { FrostbiteConnection.RaiseEvent(this.Chat.GetInvocationList(), this, cpRequestPacket.Words); } } }
protected override void DispatchAdminMovePlayerResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (PlayerMovedByAdmin != null) { int desinationTeamId; bool forceKilled; if (cpRequestPacket.Words.Count >= 4) { if (int.TryParse(cpRequestPacket.Words[2], out desinationTeamId) == true && bool.TryParse(cpRequestPacket.Words[3], out forceKilled) == true) { this.PlayerMovedByAdmin(this, cpRequestPacket.Words[1], desinationTeamId, 0, forceKilled); } } } }
public BFClient(FrostbiteConnection connection) : base(connection) { this.ResponseDelegates.Add("vars.rankLimit", this.DispatchVarsRankLimitResponse); this.ResponseDelegates.Add("vars.teamBalance", this.DispatchVarsTeamBalanceResponse); this.ResponseDelegates.Add("vars.killCam", this.DispatchVarsKillCamResponse); this.ResponseDelegates.Add("vars.miniMap", this.DispatchVarsMiniMapResponse); this.ResponseDelegates.Add("vars.crossHair", this.DispatchVarsCrossHairResponse); this.ResponseDelegates.Add("vars.3dSpotting", this.DispatchVars3dSpottingResponse); this.ResponseDelegates.Add("vars.miniMapSpotting", this.DispatchVarsMiniMapSpottingResponse); this.ResponseDelegates.Add("vars.thirdPersonVehicleCameras", this.DispatchVarsThirdPersonVehicleCamerasResponse); this.ResponseDelegates.Add("admin.password", this.DispatchVarsAdminPasswordResponse); this.GetPacketsPattern = new Regex(this.GetPacketsPattern.ToString() + "|^admin.getPlaylist|^reservedSlots.list", RegexOptions.Compiled); }
public BFBC2Client(FrostbiteConnection connection) : base(connection) { this.VersionNumberToFriendlyName = new Dictionary<string, string>(); /*{ { "571287", "R21" }, { "581637", "R22" }, { "584642", "R23" }, { "593485", "R24" }, { "602833", "R25" }, { "609063", "R26" }, { "617877", "R27" }, { "621775", "R28" } };*/ #region Map list functions this.m_responseDelegates.Add("admin.getPlaylist", this.DispatchAdminGetPlaylistResponse); this.m_responseDelegates.Add("admin.setPlaylist", this.DispatchAdminSetPlaylistResponse); // Note: These delegates point to methods in FrostbiteClient. this.m_responseDelegates.Add("admin.runNextLevel", this.DispatchAdminRunNextRoundResponse); this.m_responseDelegates.Add("admin.currentLevel", this.DispatchAdminCurrentLevelResponse); #endregion this.m_responseDelegates.Add("vars.rankLimit", this.DispatchVarsRankLimitResponse); this.m_responseDelegates.Add("vars.teamBalance", this.DispatchVarsTeamBalanceResponse); this.m_responseDelegates.Add("vars.killCam", this.DispatchVarsKillCamResponse); this.m_responseDelegates.Add("vars.miniMap", this.DispatchVarsMiniMapResponse); this.m_responseDelegates.Add("vars.crossHair", this.DispatchVarsCrossHairResponse); this.m_responseDelegates.Add("vars.3dSpotting", this.DispatchVars3dSpottingResponse); this.m_responseDelegates.Add("vars.miniMapSpotting", this.DispatchVarsMiniMapSpottingResponse); this.m_responseDelegates.Add("vars.thirdPersonVehicleCameras", this.DispatchVarsThirdPersonVehicleCamerasResponse); // Note: These delegates point to methods in FrostbiteClient. this.m_responseDelegates.Add("reservedSlots.configFile", this.DispatchReservedSlotsConfigFileResponse); this.m_responseDelegates.Add("reservedSlots.load", this.DispatchReservedSlotsLoadResponse); this.m_responseDelegates.Add("reservedSlots.save", this.DispatchReservedSlotsSaveResponse); this.m_responseDelegates.Add("reservedSlots.addPlayer", this.DispatchReservedSlotsAddPlayerResponse); this.m_responseDelegates.Add("reservedSlots.removePlayer", this.DispatchReservedSlotsRemovePlayerResponse); this.m_responseDelegates.Add("reservedSlots.clear", this.DispatchReservedSlotsClearResponse); this.m_responseDelegates.Add("reservedSlots.list", this.DispatchReservedSlotsListResponse); this.GetPacketsPattern = new Regex(this.GetPacketsPattern.ToString() + "|^admin.getPlaylist|^reservedSlots.list", RegexOptions.Compiled); }
// TO DO: Move out of FrostbiteClient. public static void RaiseEvent(Delegate[] a_delInvokes, params object[] a_objArguments) { for (int i = 0; i < a_delInvokes.Length; i++) { try { if (a_delInvokes[i].Target is Form) { if (((Form)a_delInvokes[i].Target).Disposing == false && ((Form)a_delInvokes[i].Target).IsDisposed == false && ((Form)a_delInvokes[i].Target).IsHandleCreated == true) { try { ((Control)a_delInvokes[i].Target).Invoke(a_delInvokes[i], a_objArguments); } catch (InvalidOperationException) { } } } else if (a_delInvokes[i].Target is Control) { if (((Control)a_delInvokes[i].Target).Disposing == false && ((Control)a_delInvokes[i].Target).IsDisposed == false) // { try { ((Control)a_delInvokes[i].Target).Invoke(a_delInvokes[i], a_objArguments); } catch (InvalidOperationException) { } } } else { //a_delInvokes[i].Method.Invoke(a_delInvokes[i].Target, a_objArguments); a_delInvokes[i].DynamicInvoke(a_objArguments); } } catch (Exception e) { string strParams = String.Empty; if (a_objArguments != null) { foreach (object objParam in a_objArguments) { strParams += ("---" + objParam.ToString()); } } FrostbiteConnection.LogError(String.Format("{0} ::: {1} ::: {2}", a_delInvokes[i].Target.ToString(), a_delInvokes[i].Method.ToString(), strParams), String.Empty, e); } } }
protected virtual void DispatchVarsThirdPersonVehicleCamerasResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { if (this.ThirdPersonVehicleCameras != null) { if (cpRecievedPacket.Words.Count == 2) { FrostbiteConnection.RaiseEvent(this.ThirdPersonVehicleCameras.GetInvocationList(), this, Convert.ToBoolean(cpRecievedPacket.Words[1])); } else if (cpRequestPacket.Words.Count >= 2) { FrostbiteConnection.RaiseEvent(this.ThirdPersonVehicleCameras.GetInvocationList(), this, Convert.ToBoolean(cpRequestPacket.Words[1])); } } } }
public MoHClient(FrostbiteConnection connection) : base(connection) { this.VersionNumberToFriendlyName = new Dictionary<string, string>(); /*{ { "577887", "R2" }, { "582779", "R3" }, { "586627", "R5" }, { "586981", "R6" }, { "587960", "R7" }, { "592364", "R8" }, { "615937", "R9" }, };*/ this.m_responseDelegates.Add("vars.clanTeams", this.DispatchVarsClanTeamsResponse); this.m_responseDelegates.Add("vars.noCrosshairs", this.DispatchVarsNoCrosshairsResponse); this.m_responseDelegates.Add("vars.realisticHealth", this.DispatchVarsRealisticHealthResponse); this.m_responseDelegates.Add("vars.noUnlocks", this.DispatchVarsNoUnlocksResponse); this.m_responseDelegates.Add("vars.skillLimit", this.DispatchVarsSkillLimitResponse); this.m_responseDelegates.Add("vars.noAmmoPickups", this.DispatchVarsNoAmmoPickupsResponse); this.m_responseDelegates.Add("vars.tdmScoreCounterMaxScore", this.DispatchVarsTdmScoreCounterMaxScoreResponse); // Preround vars this.m_responseDelegates.Add("vars.preRoundLimit", this.DispatchVarsPreRoundLimitResponse); this.m_responseDelegates.Add("admin.roundStartTimerEnabled", this.DispatchAdminRoundStartTimerEnabledResponse); this.m_responseDelegates.Add("vars.roundStartTimerDelay", this.DispatchVarsRoundStartTimerDelayResponse); this.m_responseDelegates.Add("vars.roundStartTimerPlayersLimit", this.DispatchVarsRoundStartTimerPlayersLimitResponse); // New map functions? this.m_responseDelegates.Add("admin.stopPreRound", this.DispatchAdminStopPreRoundResponse); // Note: These delegates point to methods in FrostbiteClient. this.m_responseDelegates.Add("reservedSpectateSlots.configFile", this.DispatchReservedSlotsConfigFileResponse); this.m_responseDelegates.Add("reservedSpectateSlots.load", this.DispatchReservedSlotsLoadResponse); this.m_responseDelegates.Add("reservedSpectateSlots.save", this.DispatchReservedSlotsSaveResponse); this.m_responseDelegates.Add("reservedSpectateSlots.addPlayer", this.DispatchReservedSlotsAddPlayerResponse); this.m_responseDelegates.Add("reservedSpectateSlots.removePlayer", this.DispatchReservedSlotsRemovePlayerResponse); this.m_responseDelegates.Add("reservedSpectateSlots.clear", this.DispatchReservedSlotsClearResponse); this.m_responseDelegates.Add("reservedSpectateSlots.list", this.DispatchReservedSlotsListResponse); this.GetPacketsPattern = new Regex(this.GetPacketsPattern.ToString() + "|^reservedSpectateSlots.list|^admin.roundStartTimerEnabled$|^admin.tdmScoreCounterMaxScore$", RegexOptions.Compiled); }
protected virtual void DispatchPlayerOnKillRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 11) { if (PlayerKilled != null) { bool headshot = false; if (bool.TryParse(cpRequestPacket.Words[4], out headshot) == true) { this.PlayerKilled(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words[3], headshot, new Point3D(cpRequestPacket.Words[5], cpRequestPacket.Words[7], cpRequestPacket.Words[6]), new Point3D(cpRequestPacket.Words[8], cpRequestPacket.Words[10], cpRequestPacket.Words[9])); } } } }
protected virtual void DispatchPlayerOnJoinRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { if (PlayerJoin != null && cpRequestPacket.Words[1].Length > 0) { this.PlayerJoin(this, cpRequestPacket.Words[1]); } } }
protected virtual void DispatchPlayerOnLeaveRequest(FrostbiteConnection sender, Packet cpRequestPacket) { // Backwards compatability //else if (cpRequestPacket.Words.Count == 2 && String.Compare(cpRequestPacket.Words[0], "player.onLeave", true) == 0) { // if (this.PlayerLeft != null) { // this.PlayerLeft(this, cpRequestPacket.Words[1], null); // } //} if (cpRequestPacket.Words.Count >= 3) { if (PlayerLeft != null) { CPlayerInfo cpiPlayer = null; List<CPlayerInfo> lstPlayers = CPlayerInfo.GetPlayerList(cpRequestPacket.Words.GetRange(2, cpRequestPacket.Words.Count - 2)); if (lstPlayers.Count > 0) { cpiPlayer = lstPlayers[0]; } this.PlayerLeft(this, cpRequestPacket.Words[1], cpiPlayer); } } }
protected virtual void DispatchPlayerOnChatRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 3) { int iTeamID = 0, iSquadID = 0; if (cpRequestPacket.Words.Count == 3) { // < R9 Support. if (GlobalChat != null) { this.GlobalChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2]); } if (TeamChat != null) { this.TeamChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], 0); } if (SquadChat != null) { this.SquadChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], 0, 0); } } else if (cpRequestPacket.Words.Count == 4 && (String.Compare(cpRequestPacket.Words[3], "all", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(cpRequestPacket.Words[3], "unknown", StringComparison.OrdinalIgnoreCase) == 0)) { // "unknown" because of BF4 beta if (GlobalChat != null) { this.GlobalChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2]); } } else if (cpRequestPacket.Words.Count >= 5 && String.Compare(cpRequestPacket.Words[3], "team", StringComparison.OrdinalIgnoreCase) == 0 && int.TryParse(cpRequestPacket.Words[4], out iTeamID) == true) { if (this.TeamChat != null) { this.TeamChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], iTeamID); } } else if (cpRequestPacket.Words.Count >= 5 && String.Compare(cpRequestPacket.Words[3], "player", StringComparison.OrdinalIgnoreCase) == 0) { if (this.PlayerChat != null) { this.PlayerChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words[4]); } } else if (cpRequestPacket.Words.Count >= 6 && String.Compare(cpRequestPacket.Words[3], "squad", StringComparison.OrdinalIgnoreCase) == 0 && int.TryParse(cpRequestPacket.Words[4], out iTeamID) == true && int.TryParse(cpRequestPacket.Words[5], out iSquadID) == true) { if (SquadChat != null) { this.SquadChat(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], iTeamID, iSquadID); } } cpRequestPacket.Words.RemoveAt(0); if (Chat != null) { this.Chat(this, cpRequestPacket.Words); } } }
// Command public virtual void DispatchResponsePacket(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRecievedPacket.Words.Count >= 1 && String.Compare(cpRecievedPacket.Words[0], "OK", StringComparison.OrdinalIgnoreCase) == 0) { if (ResponseDelegates.ContainsKey(cpRequestPacket.Words[0]) == true) { ResponseDelegates[cpRequestPacket.Words[0]](sender, cpRecievedPacket, cpRequestPacket); } } else if (cpRecievedPacket.Words.Count >= 1 && (String.Compare(cpRecievedPacket.Words[0], "InvalidPassword", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(cpRecievedPacket.Words[0], "InvalidPasswordHash", StringComparison.OrdinalIgnoreCase) == 0) && cpRequestPacket.Words.Count >= 1 && (String.Compare(cpRequestPacket.Words[0], "login.hashed", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(cpRequestPacket.Words[0], "login.plaintext", StringComparison.OrdinalIgnoreCase) == 0)) { IsLoggedIn = false; if (LoginFailure != null) { this.LoginFailure(this, cpRecievedPacket.Words[0]); } Shutdown(); } else if (cpRecievedPacket.Words.Count >= 3 && String.Compare(cpRecievedPacket.Words[0], "ScriptError", StringComparison.OrdinalIgnoreCase) == 0 && cpRequestPacket.Words.Count >= 2) { if (RunScriptError != null) { this.RunScriptError(this, "", Convert.ToInt32(cpRecievedPacket.Words[1]), cpRecievedPacket.Words[2]); } } else if (cpRecievedPacket.Words.Count == 1 && String.Compare(cpRecievedPacket.Words[0], "ExecutedOnNextRound", StringComparison.OrdinalIgnoreCase) == 0) { if (ResponseDelegates.ContainsKey(cpRequestPacket.Words[0]) == true) { ResponseDelegates[cpRequestPacket.Words[0]](sender, cpRecievedPacket, cpRequestPacket); } } // Else it is an error.. else { // InvalidArguments // TooLongMessage // InvalidDuration // InvalidFileName // InvalidLevelName // More... if (ResponseError != null) { this.ResponseError(this, cpRequestPacket, cpRecievedPacket.Words[0]); } } }
protected virtual void DispatchPunkBusterOnMessageRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { if (PunkbusterMessage != null) { this.PunkbusterMessage(this, cpRequestPacket.Words[1]); } } }
protected virtual void DispatchServerOnRoundOverPlayersRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { cpRequestPacket.Words.RemoveAt(0); if (RoundOverPlayers != null) { this.RoundOverPlayers(this, CPlayerInfo.GetPlayerList(cpRequestPacket.Words)); } } }
protected virtual void DispatchServerOnLevelStartedRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { if (LevelStarted != null) { this.LevelStarted(this); } } }
protected virtual void DispatchPlayerOnSpawnRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 9) { if (PlayerSpawned != null) { this.PlayerSpawned(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], cpRequestPacket.Words.GetRange(3, 3), cpRequestPacket.Words.GetRange(6, 3)); // new Inventory(cpRequestPacket.Words[3], cpRequestPacket.Words[4], cpRequestPacket.Words[5], cpRequestPacket.Words[6], cpRequestPacket.Words[7], cpRequestPacket.Words[8])); } } }
protected virtual void DispatchPlayerOnTeamChangeRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 4) { int iTeamID = 0, iSquadID = 0; // TO DO: Specs say TeamId and SquadId which is a little odd.. if (int.TryParse(cpRequestPacket.Words[2], out iTeamID) == true && int.TryParse(cpRequestPacket.Words[3], out iSquadID) == true) { if (PlayerChangedTeam != null) { this.PlayerChangedTeam(this, cpRequestPacket.Words[1], iTeamID, iSquadID); } } } }
protected virtual void DispatchPlayerOnKickedRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 3) { if (PlayerKicked != null) { this.PlayerKicked(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2]); } } }
protected virtual void DispatchLevelVarsGetResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRecievedPacket.Words.Count >= 2 && cpRequestPacket.Words.Count >= 2) { LevelVariable request = LevelVariable.ExtractContextVariable(false, cpRequestPacket.Words.GetRange(1, cpRequestPacket.Words.Count - 1)); request.RawValue = cpRecievedPacket.Words[1]; if (LevelVariablesGet != null) { this.LevelVariablesGet(this, request, null); } } }
protected virtual void DispatchPlayerOnSquadChangeRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 4) { int iTeamID = 0, iSquadID = 0; if (int.TryParse(cpRequestPacket.Words[2], out iTeamID) == true && int.TryParse(cpRequestPacket.Words[3], out iSquadID) == true) { if (PlayerChangedSquad != null) { this.PlayerChangedSquad(this, cpRequestPacket.Words[1], iTeamID, iSquadID); } } } }
protected virtual void DispatchLevelVarsEvaluateResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRecievedPacket.Words.Count >= 2 && cpRequestPacket.Words.Count >= 2) { var request = new LevelVariable(new LevelVariableContext(String.Empty, String.Empty), cpRequestPacket.Words[1], cpRecievedPacket.Words[1]); if (LevelVariablesEvaluate != null) { this.LevelVariablesEvaluate(this, request, null); } } }
protected virtual void DispatchServerOnLevelLoadedRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 5) { if (LevelLoaded != null) { int iRoundsPlayed = 0, iRoundsTotal = 0; if (int.TryParse(cpRequestPacket.Words[3], out iRoundsPlayed) == true && int.TryParse(cpRequestPacket.Words[4], out iRoundsTotal) == true) { this.LevelLoaded(this, cpRequestPacket.Words[1], cpRequestPacket.Words[2], iRoundsPlayed, iRoundsTotal); } } } }
protected virtual void DispatchLevelVarsClearResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { LevelVariable request = LevelVariable.ExtractContextVariable(false, cpRequestPacket.Words.GetRange(1, cpRequestPacket.Words.Count - 1)); if (LevelVariablesClear != null) { this.LevelVariablesClear(this, request); } } }
protected virtual void DispatchServerOnRoundOverRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { int iTeamID = 0; if (int.TryParse(cpRequestPacket.Words[1], out iTeamID) == true) { if (RoundOver != null) { this.RoundOver(this, iTeamID); } } } }
protected virtual void DispatchLevelVarsListResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (cpRecievedPacket.Words.Count >= 2 && cpRequestPacket.Words.Count >= 2) { LevelVariable varRequestContext = LevelVariable.ExtractContextVariable(false, cpRequestPacket.Words.GetRange(1, cpRequestPacket.Words.Count - 1)); var lstVariables = new List<LevelVariable>(); int iMatchedVariables = 0; if (int.TryParse(cpRecievedPacket.Words[1], out iMatchedVariables) == true) { for (int i = 0; i < iMatchedVariables && ((i + 1) * 4 + 2) <= cpRecievedPacket.Words.Count; i++) { lstVariables.Add(LevelVariable.ExtractContextVariable(true, cpRecievedPacket.Words.GetRange(i * 4 + 2, 4))); } if (LevelVariablesList != null) { this.LevelVariablesList(this, varRequestContext, lstVariables); } } } }
protected virtual void DispatchServerOnRoundOverTeamScoresRequest(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 2) { cpRequestPacket.Words.RemoveAt(0); if (RoundOverTeamScores != null) { this.RoundOverTeamScores(this, TeamScore.GetTeamScores(cpRequestPacket.Words)); } } }
protected virtual void DispatchAdminMovePlayerResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (PlayerMovedByAdmin != null) { if (cpRequestPacket.Words.Count >= 5) { int desinationTeamId; int destinationSquadId; bool forceKilled; if (int.TryParse(cpRequestPacket.Words[2], out desinationTeamId) == true && int.TryParse(cpRequestPacket.Words[3], out destinationSquadId) == true && bool.TryParse(cpRequestPacket.Words[4], out forceKilled) == true) { this.PlayerMovedByAdmin(this, cpRequestPacket.Words[1], desinationTeamId, destinationSquadId, forceKilled); } } } }
// Events public virtual void DispatchRequestPacket(FrostbiteConnection sender, Packet cpRequestPacket) { if (cpRequestPacket.Words.Count >= 1) { if (RequestDelegates.ContainsKey(cpRequestPacket.Words[0]) == true) { RequestDelegates[cpRequestPacket.Words[0]](sender, cpRequestPacket); } } }
protected virtual void DispatchAdminKillPlayerResponse(FrostbiteConnection sender, Packet cpRecievedPacket, Packet cpRequestPacket) { if (PlayerKilledByAdmin != null) { if (cpRequestPacket.Words.Count >= 2) { this.PlayerKilledByAdmin(this, cpRequestPacket.Words[1]); } } }