PsyOps

SQL Test

Jan 10th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. // Add the following namespaces
  6. using BattleCore;
  7. using BattleCore.Events;
  8. using System.Drawing;
  9. using System.Collections;
  10. using System.Data;
  11.  
  12. namespace Behaviors
  13. {
  14. // Add the attribute and the base class
  15. [Behavior ("BotTest", "true", "0.1", "udp", "Testing misc stuff")]
  16. [CommandHelp("!sql", "Runs an SQL transaction", ModLevels.SMod)]
  17. public class BotTest : BotEventListener
  18. {
  19. private PlayerPositionEvent myPosition = new PlayerPositionEvent();
  20.  
  21. // Bot Test
  22. public BotTest ()
  23. {
  24. //Command registration
  25. RegisterCommand("!sql", HandleSqlEvent);
  26. RegisterCommand("!die", HandleDieEvent);
  27. RegisterCommand("!bomb", HandleBombEvent);
  28. RegisterTimedEvent("Bombs", 100, ShootBomb);
  29. }
  30.  
  31. public void ShootBomb ()
  32. {
  33. myPosition.Weapon.Type = WeaponTypes.BounceBullet;
  34. myPosition.Weapon.Level = 2;
  35. myPosition.ShipRotation += 1;
  36. SendGameEvent (myPosition);
  37. }
  38.  
  39. public void HandleDieEvent(ChatEvent e)
  40. {
  41. PlayerDeathEvent evt = new PlayerDeathEvent();
  42. evt.Bounty = 100;
  43. evt.KillerName = "UDP";
  44. SendGameEvent(evt);
  45. }
  46.  
  47. public void HandleBombEvent(ChatEvent e)
  48. {
  49. myPosition.Weapon.Type = WeaponTypes.ProxBomb;
  50. myPosition.Weapon.Level = 2;
  51. SendGameEvent (myPosition);
  52.  
  53. }
  54.  
  55. public void PlayerPosition(object sender, PlayerPositionEvent e)
  56. {
  57. if (e.PlayerName == "UDP")
  58. {
  59. myPosition.VelocityX = e.VelocityX;
  60. myPosition.VelocityY = e.VelocityY;
  61. myPosition.MapPositionY = e.MapPositionY;
  62. myPosition.MapPositionX = e.MapPositionX;
  63.  
  64. SendGameEvent(e);
  65. }
  66. }
  67.  
  68. // Execute the Sql command
  69. public void HandleSqlEvent(ChatEvent e)
  70. {
  71. if (e.ModLevel >= ModLevels.SMod && e.Message.Length > 5)
  72. {
  73.  
  74. string commandTest = e.Message.Substring(5);
  75.  
  76. if (commandTest.StartsWith("SELECT", true, null))
  77. {
  78. SqlQueryEvent sqlEvent = new SqlQueryEvent();
  79. sqlEvent.Command.CommandText = e.Message.Substring(5);
  80. SendGameEvent(sqlEvent);
  81. }
  82. else
  83. {
  84. SqlCommandEvent sqlEvent = new SqlCommandEvent();
  85. sqlEvent.Command.CommandText = e.Message.Substring(5);
  86. SendGameEvent(sqlEvent);
  87. }
  88. }
  89. }
  90.  
  91. public void OnSqlEvent(object sender, SqlQueryEvent e)
  92. {
  93. ChatEvent ce = new ChatEvent();
  94. ce.Message = "Records Affected = " + e.RecordsAffected;
  95. SendGameEvent(ce);
  96.  
  97. // For each table in the DataSet, print the values of each row.
  98. foreach (DataRow row in e.QueryData.Rows)
  99. {
  100. String nextRecord = "Row:";
  101.  
  102. foreach (DataColumn column in e.QueryData.Columns)
  103. {
  104. nextRecord += " " + (row[column]).ToString();
  105. }
  106.  
  107. ce.Message = nextRecord;
  108. SendGameEvent(ce);
  109. }
  110. }
  111.  
  112. public void OnSqlEvent(object sender, SqlCommandEvent e)
  113. {
  114. ChatEvent ce = new ChatEvent();
  115. ce.Message = "Records Affected = " + e.RecordsAffected;
  116. SendGameEvent (ce);
  117. }
  118.  
  119. public void OnListModEvent(object sender, ListModEvent e)
  120. {
  121. Console.WriteLine(e.Moderator.PlayerName + " - " + e.Moderator.ModeratorLevel);
  122. }
  123.  
  124.  
  125. // This method is required by the base class
  126. // perform any cleanup here
  127. public override void Dispose ()
  128. {
  129. }
  130.  
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment