Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '*****************************************************************
  2. 'modCentinela.bas - ImperiumAO - v1.2
  3. '
  4. 'Funciónes de control para usuarios que se encuentran trabajando
  5. '
  6. '*****************************************************************
  7. 'Respective portions copyrighted by contributors listed below.
  8. '
  9. 'This program is free software; you can redistribute it and/or modify
  10. 'it under the terms of the Affero General Public License;
  11. 'either version 1 of the License, or any later version.
  12. '
  13. 'This program is distributed in the hope that it will be useful,
  14. 'but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. 'Affero General Public License for more details.
  17. '
  18. 'You should have received a copy of the Affero General Public License
  19. 'along with this program; if not, you can find it at http://www.affero.org/oagpl.html
  20.  
  21. '*****************************************************************
  22. 'Augusto Rando(barrin@imperiumao.com.ar)
  23. '   ImperiumAO 1.2
  24. '   - First Relase
  25. '
  26. 'Juan Martín Sotuyo Dodero (juansotuyo@gmail.com)
  27. '   Alkon AO 0.11.5
  28. '   - Small improvements and added logs to detect possible cheaters
  29. '
  30. 'Juan Martín Sotuyo Dodero (juansotuyo@gmail.com)
  31. '   Alkon AO 0.12.0
  32. '   - Added several messages to spam users until they reply
  33. '*****************************************************************
  34.  
  35. Option Explicit
  36.  
  37. Private Const NPC_CENTINELA_TIERRA As Integer = 16  'Índice del NPC en el .dat
  38. Private Const NPC_CENTINELA_AGUA As Integer = 16    'Ídem anterior, pero en mapas de agua
  39.  
  40. Public CentinelaNPCIndex As Integer                'Índice del NPC en el servidor
  41.  
  42. Private Const TIEMPO_INICIAL As Byte = 2 'Tiempo inicial en minutos. No reducir sin antes revisar el timer que maneja estos datos.
  43.  
  44. Private Type tCentinela
  45.     RevisandoUserIndex As Integer   '¿Qué índice revisamos?
  46.    TiempoRestante As Integer       '¿Cuántos minutos le quedan al usuario?
  47.    clave As Integer                'Clave que debe escribir
  48.    spawnTime As Long
  49. End Type
  50.  
  51. Public centinelaActivado As Boolean
  52.  
  53. Public Centinela As tCentinela
  54.  
  55. Public Sub CallUserAttention()
  56. '############################################################
  57. 'Makes noise and FX to call the user's attention.
  58. '############################################################
  59.    If (GetTickCount() And &H7FFFFFFF) - Centinela.spawnTime >= 5000 Then
  60.         If Centinela.RevisandoUserIndex <> 0 And centinelaActivado Then
  61.             If Not UserList(Centinela.RevisandoUserIndex).flags.CentinelaOK Then
  62.                 Call WritePlayWave(Centinela.RevisandoUserIndex, SND_WARP, Npclist(CentinelaNPCIndex).Pos.X, Npclist(CentinelaNPCIndex).Pos.Y)
  63.                 Call WriteCreateFX(Centinela.RevisandoUserIndex, Npclist(CentinelaNPCIndex).Char.CharIndex, FXIDs.FXWARP, 0)
  64.                
  65.                 'Resend the key
  66.                Call CentinelaSendClave(Centinela.RevisandoUserIndex)
  67.                
  68.                 Call FlushBuffer(Centinela.RevisandoUserIndex)
  69.             End If
  70.         End If
  71.     End If
  72. End Sub
  73.  
  74. Private Sub GoToNextWorkingChar()
  75. '############################################################
  76. 'Va al siguiente usuario que se encuentre trabajando
  77. '############################################################
  78.    Dim LoopC As Long
  79.    
  80.     For LoopC = 1 To LastUser
  81.         If UserList(LoopC).flags.UserLogged And UserList(LoopC).Counters.Trabajando > 0 And (UserList(LoopC).flags.Privilegios And PlayerType.User) Then
  82.             If Not UserList(LoopC).flags.CentinelaOK Then
  83.                 'Inicializamos
  84.                Centinela.RevisandoUserIndex = LoopC
  85.                 Centinela.TiempoRestante = TIEMPO_INICIAL
  86.                 Centinela.clave = RandomNumber(1, 32000)
  87.                 Centinela.spawnTime = GetTickCount() And &H7FFFFFFF
  88.                
  89.                 'Ponemos al centinela en posición
  90.                Call WarpCentinela(LoopC)
  91.                
  92.                 If CentinelaNPCIndex Then
  93.                     'Mandamos el mensaje (el centinela habla y aparece en consola para que no haya dudas)
  94.                    Call WriteChatOverHead(LoopC, "Saludos " & UserList(LoopC).Name & ", soy el Centinela de estas tierras. Me gustaría que escribas /CENTINELA " & Centinela.clave & " en no más de dos minutos.", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbGreen)
  95.                     Call WriteConsoleMsg(LoopC, "Saludos " & UserList(LoopC).Name & ", soy el Centinela de estas tierras. Me gustaría que escribas /CENTINELA " & Centinela.clave & " en no más de dos minutos.", FontTypeNames.FONTTYPE_CENTINELA)
  96.                     Call FlushBuffer(LoopC)
  97.                 End If
  98.                 Exit Sub
  99.             End If
  100.         End If
  101.     Next LoopC
  102.    
  103.     'No hay chars trabajando, eliminamos el NPC si todavía estaba en algún lado y esperamos otro minuto
  104.    If CentinelaNPCIndex Then
  105.         Call QuitarNPC(CentinelaNPCIndex)
  106.         CentinelaNPCIndex = 0
  107.     End If
  108.    
  109.     'No estamos revisando a nadie
  110.    Centinela.RevisandoUserIndex = 0
  111. End Sub
  112.  
  113. Private Sub CentinelaFinalCheck()
  114. '############################################################
  115. 'Al finalizar el tiempo, se retira y realiza la acción
  116. 'pertinente dependiendo del caso
  117. '############################################################
  118. On Error GoTo Error_Handler
  119.     Dim Name As String
  120.     Dim numPenas As Integer
  121.    
  122.     If Not UserList(Centinela.RevisandoUserIndex).flags.CentinelaOK Then
  123.         'Logueamos el evento
  124.        Call LogCentinela("Centinela baneo a " & UserList(Centinela.RevisandoUserIndex).Name & " por uso de macro inasistido")
  125.        
  126.         'Ponemos el ban
  127.        UserList(Centinela.RevisandoUserIndex).flags.Ban = 1
  128.        
  129.         Name = UserList(Centinela.RevisandoUserIndex).Name
  130.        
  131.         'Avisamos a los admins
  132.        Call SendData(SendTarget.ToAdmins, 0, PrepareMessageConsoleMsg("Servidor> El centinela ha baneado a " & Name, FontTypeNames.FONTTYPE_SERVER))
  133.        
  134.         'ponemos el flag de ban a 1
  135.        Call WriteVar(CharPath & Name & ".chr", "FLAGS", "Ban", "1")
  136.         'ponemos la pena
  137.        numPenas = val(GetVar(CharPath & Name & ".chr", "PENAS", "Cant"))
  138.         Call WriteVar(CharPath & Name & ".chr", "PENAS", "Cant", numPenas + 1)
  139.         Call WriteVar(CharPath & Name & ".chr", "PENAS", "P" & numPenas + 1, "CENTINELA : BAN POR MACRO INASISTIDO " & Date & " " & time)
  140.        
  141.         'Evitamos loguear el logout
  142.        Dim index As Integer
  143.         index = Centinela.RevisandoUserIndex
  144.         Centinela.RevisandoUserIndex = 0
  145.        
  146.         Call CloseSocket(index)
  147.     End If
  148.    
  149.     Centinela.clave = 0
  150.     Centinela.TiempoRestante = 0
  151.     Centinela.RevisandoUserIndex = 0
  152.    
  153.     If CentinelaNPCIndex Then
  154.         Call QuitarNPC(CentinelaNPCIndex)
  155.         CentinelaNPCIndex = 0
  156.     End If
  157. Exit Sub
  158.  
  159. Error_Handler:
  160.     Centinela.clave = 0
  161.     Centinela.TiempoRestante = 0
  162.     Centinela.RevisandoUserIndex = 0
  163.    
  164.     If CentinelaNPCIndex Then
  165.         Call QuitarNPC(CentinelaNPCIndex)
  166.         CentinelaNPCIndex = 0
  167.     End If
  168.    
  169.     Call LogError("Error en el checkeo del centinela: " & Err.description)
  170. End Sub
  171.  
  172. Public Sub CentinelaCheckClave(ByVal UserIndex As Integer, ByVal clave As Integer)
  173. '############################################################
  174. 'Corrobora la clave que le envia el usuario
  175. '############################################################
  176.    If clave = Centinela.clave And UserIndex = Centinela.RevisandoUserIndex Then
  177.         UserList(Centinela.RevisandoUserIndex).flags.CentinelaOK = True
  178.         Call WriteChatOverHead(UserIndex, "¡Muchas gracias " & UserList(Centinela.RevisandoUserIndex).Name & "! Espero no haber sido una molestia", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbWhite)
  179.         Centinela.RevisandoUserIndex = 0
  180.         Call FlushBuffer(UserIndex)
  181.     Else
  182.         Call CentinelaSendClave(UserIndex)
  183.        
  184.         'Logueamos el evento
  185.        If UserIndex <> Centinela.RevisandoUserIndex Then
  186.             Call LogCentinela("El usuario " & UserList(UserIndex).Name & " respondió aunque no se le hablaba a él.")
  187.         Else
  188.             Call LogCentinela("El usuario " & UserList(UserIndex).Name & " respondió una clave incorrecta: " & clave & " - Se esperaba : " & Centinela.clave)
  189.         End If
  190.     End If
  191. End Sub
  192.  
  193. Public Sub ResetCentinelaInfo()
  194. '############################################################
  195. 'Cada determinada cantidad de tiempo, volvemos a revisar
  196. '############################################################
  197.    Dim LoopC As Long
  198.    
  199.     For LoopC = 1 To LastUser
  200.         If (LenB(UserList(LoopC).Name) <> 0 And LoopC <> Centinela.RevisandoUserIndex) Then
  201.             UserList(LoopC).flags.CentinelaOK = False
  202.         End If
  203.     Next LoopC
  204. End Sub
  205.  
  206. Public Sub CentinelaSendClave(ByVal UserIndex As Integer)
  207. '############################################################
  208. 'Enviamos al usuario la clave vía el personaje centinela
  209. '############################################################
  210.    If CentinelaNPCIndex = 0 Then Exit Sub
  211.    
  212.     If UserIndex = Centinela.RevisandoUserIndex Then
  213.         If Not UserList(UserIndex).flags.CentinelaOK Then
  214.             Call WriteChatOverHead(UserIndex, "¡La clave que te he dicho es /CENTINELA " & Centinela.clave & ", escríbelo rápido!", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbGreen)
  215.             Call WriteConsoleMsg(UserIndex, "¡La clave correcta es /CENTINELA " & Centinela.clave & ", escríbelo rápido!", FontTypeNames.FONTTYPE_CENTINELA)
  216.         Else
  217.             'Logueamos el evento
  218.            Call LogCentinela("El usuario " & UserList(Centinela.RevisandoUserIndex).Name & " respondió más de una vez la contraseña correcta.")
  219.             Call WriteChatOverHead(UserIndex, "Te agradezco, pero ya me has respondido. Me retiraré pronto.", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbGreen)
  220.         End If
  221.     Else
  222.         Call WriteChatOverHead(UserIndex, "No es a ti a quien estoy hablando, ¿no ves?", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbWhite)
  223.     End If
  224. End Sub
  225.  
  226. Public Sub PasarMinutoCentinela()
  227. '############################################################
  228. 'Control del timer. Llamado cada un minuto.
  229. '############################################################
  230.    If Not centinelaActivado Then Exit Sub
  231.    
  232.     If Centinela.RevisandoUserIndex = 0 Then
  233.         Call GoToNextWorkingChar
  234.     Else
  235.         Centinela.TiempoRestante = Centinela.TiempoRestante - 1
  236.        
  237.         If Centinela.TiempoRestante = 0 Then
  238.             Call CentinelaFinalCheck
  239.             Call GoToNextWorkingChar
  240.         Else
  241.             'Recordamos al user que debe escribir
  242.            If Matematicas.Distancia(Npclist(CentinelaNPCIndex).Pos, UserList(Centinela.RevisandoUserIndex).Pos) > 5 Then
  243.                 Call WarpCentinela(Centinela.RevisandoUserIndex)
  244.             End If
  245.            
  246.             'El centinela habla y se manda a consola para que no quepan dudas
  247.            Call WriteChatOverHead(Centinela.RevisandoUserIndex, "¡" & UserList(Centinela.RevisandoUserIndex).Name & ", tienes un minuto más para responder! Debes escribir /CENTINELA " & Centinela.clave & ".", CStr(Npclist(CentinelaNPCIndex).Char.CharIndex), vbRed)
  248.             Call WriteConsoleMsg(Centinela.RevisandoUserIndex, "¡" & UserList(Centinela.RevisandoUserIndex).Name & ", tienes un minuto más para responder! Debes escribir /CENTINELA " & Centinela.clave & ".", FontTypeNames.FONTTYPE_CENTINELA)
  249.             Call FlushBuffer(Centinela.RevisandoUserIndex)
  250.         End If
  251.     End If
  252. End Sub
  253.  
  254. Private Sub WarpCentinela(ByVal UserIndex As Integer)
  255. '############################################################
  256. 'Inciamos la revisión del usuario UserIndex
  257. '############################################################
  258.    'Evitamos conflictos de índices
  259.    If CentinelaNPCIndex Then
  260.         Call QuitarNPC(CentinelaNPCIndex)
  261.         CentinelaNPCIndex = 0
  262.     End If
  263.    
  264.     If HayAgua(UserList(UserIndex).Pos.Map, UserList(UserIndex).Pos.X, UserList(UserIndex).Pos.Y) Then
  265.         CentinelaNPCIndex = SpawnNpc(NPC_CENTINELA_AGUA, UserList(UserIndex).Pos, True, False)
  266.     Else
  267.         CentinelaNPCIndex = SpawnNpc(NPC_CENTINELA_TIERRA, UserList(UserIndex).Pos, True, False)
  268.     End If
  269.    
  270.     'Si no pudimos crear el NPC, seguimos esperando a poder hacerlo
  271.    If CentinelaNPCIndex = 0 Then _
  272.         Centinela.RevisandoUserIndex = 0
  273. End Sub
  274.  
  275. Public Sub CentinelaUserLogout()
  276. '############################################################
  277. 'El usuario al que revisabamos se desconectó
  278. '############################################################
  279.    If Centinela.RevisandoUserIndex Then
  280.         'Logueamos el evento
  281.        Call LogCentinela("El usuario " & UserList(Centinela.RevisandoUserIndex).Name & " se desolgueó al pedirsele la contraseña")
  282.        
  283.         'Reseteamos y esperamos a otro PasarMinuto para ir al siguiente user
  284.        Centinela.clave = 0
  285.         Centinela.TiempoRestante = 0
  286.         Centinela.RevisandoUserIndex = 0
  287.        
  288.         If CentinelaNPCIndex Then
  289.             Call QuitarNPC(CentinelaNPCIndex)
  290.             CentinelaNPCIndex = 0
  291.         End If
  292.     End If
  293. End Sub
  294.  
  295. Private Sub LogCentinela(ByVal texto As String)
  296. '*************************************************
  297. 'Author: Juan Martín Sotuyo Dodero (Maraxus)
  298. 'Last modified: 03/15/2006
  299. 'Loguea un evento del centinela
  300. '*************************************************
  301. On Error GoTo Errhandler
  302.  
  303.     Dim nfile As Integer
  304.     nfile = FreeFile ' obtenemos un canal
  305.    
  306.     Open App.Path & "\logs\Centinela.log" For Append Shared As #nfile
  307.     Print #nfile, Date & " " & time & " " & texto
  308.     Close #nfile
  309. Exit Sub
  310.  
  311. Errhandler:
  312. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement