• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - NicoQwertyu

#1
.NET Platform / Re: Connection to MySQL
April 13, 2008, 02:08 AM
QuoteThe problem is that, right now, it seems that I have to manually add IP's to the access list just to let login to the database. I was wondering if I set up a wildcard in the access list that allows all IPs(which in turn would allow anyone using my program at least try to login), would that compromise a lot of security to databases?

Yes, you can use a wildcard rather than specific IP addresses. Yes, allowing any IP address to access your server compromises security. However, that is how information security works; you need for find a balance between security and availability.
#2
Warcraft / Re: Post your latest uber screenshots
March 27, 2008, 06:38 PM
These screenshots catalogue my priest's lifetime from 1-70. As of the newest patch, many of these places are unreachable.

Rest in piece, WoW Exploration:



















#3
C/C++ Programming / Re: BitBlt?
March 26, 2008, 09:56 PM
I was able to use Window GDI to "blt" an image onto a rich text box, but there was a problem. By letting the RTB redraw itself, then posting an image over it, I would draw over all the text/scroll bars/borders. By drawing my image, and then letting the RTB redraw itself, it would draw over my image.

The only way to do this, that I've found, is to literally draw everything manually, the image, the text, the scroll bars, the borders, etc...



    Public Property Backimage() As Image
        Get
            Return _backimage
        End Get
        Set(ByVal value As Image)
            _backimage = value
        End Set
    End Property

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)
        If m.Msg = WM_PAINT And _backimage IsNot Nothing Then
            Dim hdc As Integer = GetWindowDC(Me.Handle)
            Using g As Graphics = Graphics.FromHdc(hdc)
                Using myfont As New Font("Times New Roman", 10, FontStyle.Bold)
                    g.DrawImage(Me.Backimage, 0, 0, Me.Width, Me.Height)
                    g.DrawString(Me.Text, myfont, Brushes.Black, 0, 0)
                End Using
            End Using
            ReleaseDC(Me.Handle, hdc)
        End If
    End Sub


Oh, and to answer your question, I had to redraw the image every time the RTB received the WM_PAINT message.
#4
Visual Basic Programming / Re: Audio and WINE
March 26, 2008, 12:59 PM
Quote from: Andy on March 26, 2008, 05:00 AM
I just don't know which would be best for WINE compatibility...

Both quartz and winmm are supported by WINE, but I would personally go with winmm.dll--it seems to have more implemented.
#5
Visual Basic Programming / Re: Audio and WINE
March 25, 2008, 10:30 PM
http://source.winehq.org/WineAPI/winmm.html
http://msdn2.microsoft.com/en-us/library/ms712879(VS.85).aspx

Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Quote from: Andy on March 25, 2008, 08:53 PM
I really wish I could send data directly to the sound card, but whatever.
I don't think I'd want/trust a program on my computer that tried to directly access my hardware. I'd rather let my operating system and drivers handle that mess.
#6
Quote from: Andy on March 25, 2008, 08:51 PM
double backslash ftw. I'll have to make a note of that, just in case...

AFAIK the double backslash is a language specific rule; you don't need to worry about it with VB.
#7
C/C++ Programming / Re: Data Types and Sockets
March 24, 2008, 11:06 PM
Quotevoid * memset ( void * ptr, int value, size_t num );   <cstring>


Fill block of memory

Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).

The size of the packet shouldn't make a difference. Isn't a WORD two bytes though? Would you want:
memset(sendbuffer, pbufferlen, 2);?
#8
.NET Platform / Database Class
March 24, 2008, 09:48 PM
Well, I finally managed to make my first piece of reusable code in VB.NET, and I'd like to share it with the community.  Maybe it will be useful to someone, maybe it will end up being an example of what not to do. ;D

Abstract Class Database:
Public MustOverride Property Table() As String
Public MustOverride Property Filename() As String
Public MustOverride ReadOnly Property Position() As Integer
Public MustOverride ReadOnly Property Count() As Integer
Public MustOverride Overloads Function GetRecord(ByVal column As String) As String
Public MustOverride Overloads Function GetRecord() As String
Public MustOverride Function EndOfTable() As Boolean
Public MustOverride Sub GoToEnd()
Public MustOverride Sub GoToBeginning()
Public MustOverride Sub NextRecord()
Public MustOverride Sub PreviousRecord()


Class MsAccessDatabase : Inherits Database : Implements IDisposable:
Constructor overloads:
Public Sub New(ByVal filename As String)
Public Sub New(ByVal filename As String, ByVal table As String)
Public Sub New(ByVal filename As String, ByVal table As String, ByVal query As String)
Public Methods:
Public Overloads Sub AddTable(ByVal table As String)
Public Overloads Sub AddTable(ByVal table As String, ByVal query As String)
Private Methods:
Private Sub SetPosition(ByVal newpos As Integer)
Private Sub IncrementPosition()
Private Sub DecrementPosition()
Private Sub CreateConnection(ByVal filename As String)
Private Sub CreateAdapter(ByVal query As String)
Private Sub CreateDataset()

Class SQLDatabase : Inherits Database:
'Unimplemented

Class OracleDatabase : Inherits Database:
'Unimplemented

Test database used:


Simple Example Usage:


Imports Asylum.Database

        Using myDatabase As MsAccessDatabase = New MsAccessDatabase("C:\Documents and Settings\Kyle\My Documents\Simple Database.mdb")
            myDatabase.AddTable("Users")
            myDatabase.AddTable("UserSettings")
            myDatabase.AddTable("GlobalSettings")
            myDatabase.Table = "Users"
            Do Until myDatabase.EndOfTable = True
                'Manually specify a column: myDatabase.GetRecord("Username")
                'Manually specify a column: myDatabase.GetRecord("Access")

                'myDatabase.GetRecord() will return the record of the first column in the table
                'In this example, this is the same as myDatabase.GetRecord("Username")
                'DoSomething >_<
            Loop

            myDatabase.Table = "GlobalSettings"
            'Etc...
        End Using


When you change tables with the Database.Table property, Database.Position will automatically be reset to 0. Querys can be specified instead of the default "SELECT * FROM " in one of the constructor overloads.

Example query usage:

        Using myDatabase As MsAccessDatabase = New MsAccessDatabase("C:\Documents and Settings\Kyle\My Documents\Simple Database.mdb", _
                                                          "Users", "SELECT Username FROM ")
            '...
        End Using





Link to database classes:



  • Right click + Save as...
  • Change extension from .jpg to .rar
  • Extract files...


Edit: Well, I was so excited to post this that I forgot to add ChangeRecord, and Save methods. I tried to update it to allow this functionality, but couldn't figure it out. OleDBDataAdapter.Update kept throwing exceptions. So all the classes can do in their current state is READ databases. But enjoy anyway, it was fun coding.
#9
General Discussion / Re: Lolcats!
March 24, 2008, 01:07 PM


#10
General Discussion / Re: Lolc"h"ats!
March 24, 2008, 12:59 PM
Quote from: betawarz on February 15, 2008, 08:37 AM
here's me owning tgk...

How old is that picture?

Edit:

Silly TGK.


#11
C/C++ Programming / Re: Data Types and Sockets
March 23, 2008, 03:26 PM
Quote from: FrostWraith on March 23, 2008, 11:03 AM
One last thing is whether or not I should be doing connect() or WSAConnect().  Which is more up to date?  Which is better and for what reasons?

AFAIK, WSAConnect() supports more options at connection time, such as a QoS request and some connect data used for legacy protocols such as DECNet and OSI TP4. For what you're doing, use connect(). If you want to read more, the link to the MSDN page is here.
#12
.NET Platform / Re: Object Oriented Design Help
March 23, 2008, 02:14 PM
First off, thank you for making that long post, and keeping it simple for me.

QuoteThis object will be the overall [core bot] class, and further bot objects with more features will derive off it.
Derive off it -- as in [core bot] will inherit the methods and properties of all other classes built around it? I doubt that's what you were trying to explain, but that's how I read it.  :-[

QuoteAnyway, getting back on track. In VB.NET, setting something to 'Nothing' just changes what the reference to the object (being the variable) is treated as. It doesn't do any explicit memory freeing, nor does it even call the Dispose() method. When the object goes out of scope, it will be handled like any other dynamically allocated object through .NET's garbage collection.

Back in your code again, for that scenario, I don't think you'd need to implement IDisposable. As I said before, the idea of it is to provide a way of telling an object that it needs to clean up it's unmanaged resources. For example, connecting to a SQL Database to read/write a bunch of data, or opening a file to read/write a bunch of data, etc. Holding onto that connection, or keeping the file handle open until the garbage collection gets around will waste resources. It will also prevent that file being accessed until it's handle is closed. By implementing IDisposable in those cases creates an insurance that once you've finished working with them, they'll be freed up properly.
Is the massive List(of T) I have floating around in memory an unmanaged resource?

QuoteA note with your code, I wouldn't use a Try/Catch in a situation where I could prevent it. For example, you have:
Ah, thank you. I love learning the correct way to code things. I knew I could throw my own exceptions, but it's something I've never done before. Now I know how.  :)

QuoteThe Tag class seems quite redundant and using lists of strings would do just fine.
You're right. I can't even come up with an excuse as to why I did that in the first place. Fixed.

QuoteAlso, why does your User class have a Password property? Here's some things I'd have for a User:
I just used the first three properties that came to mind. I'm not writing a real bot, I'm just trying to learn the language by writing little mini-projects. Bots are something I've always been familiar and comfortable with, so I'm starting with that. I'd much rather learn .NET by making little pieces of a bot, rather than try to write the software for an ATM machine.

QuoteNow, although the property User.ChannelInfo.Index isn't required internally, it is handy to place ...
Speaking of the channel list, I had a little epiphany this morning while walking circles around the island in my kitchen, eating my egg/bacon sandwich. Although some of my code isn't reusable in the sense than I can just plug it in and go to town on any database, it can be reusable in my own project.

The channellist can inherit databasecore, and add a few methods for manipulating the control on the form, and changing icons. The user objects in the channel can derive from Database.User, and just add a few more properties for ping and icon. So it's not a total failure.

Edit: Well, the above is almost true. It's kind of impossible to implement without overriding just about everything, however.  >:(
#13
.NET Platform / Re: Object Oriented Design Help
March 22, 2008, 09:43 PM
If you can find the time and patience, look through what I've written:

Tag.vb
Namespace Database
    Public Class Tag
        Private _tag As String
        Public Property Tag() As String
            Get
                Return _tag
            End Get
            Set(ByVal value As String)
                If value IsNot Nothing Then _tag = value
            End Set
        End Property
    End Class
End Namespace


User.vb
Namespace Database
    Public Class User
        Protected _username As String
        Protected _password As String
        Protected _access As Integer

#Region "Properties"
        Public Property Username() As String
            Get
                Return _username
            End Get
            Set(ByVal value As String)
                If value IsNot Nothing Then _username = value
            End Set
        End Property

        Public Property Password() As String
            Get
                Return _password
            End Get
            Set(ByVal value As String)
                If value IsNot Nothing Then _password = value
            End Set
        End Property

        Public Property Access() As Integer
            Get
                Return _access
            End Get
            Set(ByVal value As Integer)
                _access = value
            End Set
        End Property
#End Region

    End Class
End Namespace


DatabaseCore.vb
Imports Bot.Database
Imports System
Imports System.Collections.Generic

Public Class DatabaseCore : Implements IDisposable

    Protected _userList As List(Of User)
    Protected _safeList As List(Of Tag)
    Protected _shitList As List(Of Tag)

    Public Sub New()
        _userList = New List(Of User)
        _safeList = New List(Of Tag)
        _shitList = New List(Of Tag)
    End Sub

    Public Sub AddUser(ByVal newUsername As String, ByVal newPassword As String, ByVal newAccess As Integer)
        If newUsername IsNot Nothing And newPassword IsNot Nothing Then
            Dim u As User = New User
            With u
                .Username = newUsername
                .Password = newPassword
                .Access = newAccess
            End With
            _userList.Add(u)
        End If
    End Sub

    Public Sub AddSafelist(ByVal newTag As String)
        If newTag IsNot Nothing Then
            Dim t As Tag = New Tag
            t.Tag = newTag
            _safeList.Add(t)
        End If
    End Sub

    Public Sub AddShitlist(ByVal newTag As String)
        If newTag IsNot Nothing Then
            Dim t As Tag = New Tag
            t.Tag = newTag
            _shitList.Add(t)
        End If
    End Sub

    Public Function GetUser(ByVal index As Integer) As String
        Try
            Return _userList(index).Username
        Catch ex As ArgumentOutOfRangeException
            Return "Out of bounds exception! The index supplied does not correspond to a user!" 'Is there a better way to do this?
        End Try
    End Function

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free other state (managed objects).

                ' I don't know what a managed object is! :D
            End If

            ' TODO: free your own state (unmanaged objects).
            ' TODO: set large fields to null.

            ' I think these are unmanaged objects! :D
            _userList = Nothing
            _shitList = Nothing
            _safeList = Nothing
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

I don't know if implementing IDisposable is necessary, but I remember seeing you talk about it in a previous post, and I'm trying to get everything right.

Usage:
Imports Bot
Imports Bot.Database
Public Class uiMainForm

    Private Sub uiMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim userDatabase As DatabaseCore = New DatabaseCore
        userDatabase.AddUser("Kyle", "abc123!@", 1)
        userDatabase.AddUser("Asylum", "abc123!@", 1)
        MessageBox.Show(userDatabase.GetUser(0))
        MessageBox.Show(userDatabase.GetUser(1))
        MessageBox.Show(userDatabase.GetUser(2))
    End Sub
End Class

Outputs:
Kyle
Asylum
Index out of bounds...


I want to appologize. I know you're trying to help me the best you can, and I'm just not seeming to get it. While this implementation will work, I'm essentially just having a class pass some glorified structs around. I originally started trying to inherit my superclass (DatabaseCore), but it ended up being pointless because of the way I designed it. What would I need to do to make this follow the object oriented model more appropriately?
#14
.NET Platform / Re: Object Oriented Design Help
March 22, 2008, 07:27 PM
QuoteYes, this implementation is thread-safe (depending on what you mean by it).  In the traditional sense of "thread-safe," you're not going to run into problems with the incBuffer having collisions, because incBuffer is declared locally to the method.  Since each thread gets its own local variable and call stack, you don't need to worry about incBuffer on Thread A colliding with incBuffer on Thread B - they're in different memory.
You assumed right. That's what I ment.

QuoteVery usually, we make a base class called Entity that each of these can derive from.  It allows us to sometimes give additional functionality to database entity objects.
So you do generally have to recode the database stuff though? You don't just reuse a few classes and build from there?

#15
Quote from: Andy on March 11, 2008, 03:31 PM
Yep. But never mind... I'm not really working on my BNCS emulator at the moment, nor in the foreseeable future... Other projects have cropped up.

Just in case anyone wanders in here wanting to know, here's a few of them I can remember off the top of my head.

    2010 NAME Username
    This is sent to the user immediately upon logging on, and tells the user what name he was given. This is a legacy thing and isn't really used anymore. It was for when users logged on as Guest, or logged onto the same name multiple times: Guest#3, Massbot#1, Massbot#2, etc. Blizzard has since removed that ability, but this 2010 message remains.

    1007 CHANNEL "Channel Name"
    This is sent when you successfully join a channel. If you are banned, or the channel is special somehow, you simply won't recieve this message, and will instead receive a 1019 ERROR message informing you of what went wrong.

    1001 USER Username Flags Client
    After joining a channel, each user currently in the channel will be displayed with this line (including yourself).

    1009 USER Username Flags Client
    This is sent when a user's flags have changed: user gains operator status, user becomes squelched, users logs in as an admin, etc.

    1002 JOIN Username Flags Client
    This will be sent when another user joins a channel. You will not see your own JOIN broadcast.

    1003 LEAVE Username Flags
    This is sent when another user leaves a channel. You will not see your own LEAVE broadcast.

    1005 TALK Username Flags "Message"
    When a user talks. You will not see your own TALK broadcast, however, the server will generally echo back what you type, depending on how you log in (0x03/0x04).

    1018 INFO "Server info"
    Server info. ie: "1018 INFO "Welcome to
Battle.Net!"

1019 ERROR "Error"
Server error. ie: "1019 ERROR "You are banned from that channel!"

2000 NULL
This is sent every five minutes, and is used as a keepalive. It is not required that the user reply to these messages. However, it works for a decent 5 minute anti-idle. ;)

1004 WHISPER Username Flags "Message"
Whisper from.

1010 WHISPER Username Flags "Message"
Whisper to.

1023 EMOTE Username Flags "Message"

1006 _____ "Message"
This was used for admin broadcasts. I can't remember what came after 1006, but it may have been INFO.[/list]

Here is a basic idea of how the server will communicate.

Quote
Connection from [127.0.0.1]

Enter your account name and password.
Use 'anonymous' if you only want to issue queries.

Username: Asylum
Password:

2010 NAME Asylum
1007 CHANNEL "Public Chat 1"
1001 USER Asylum 0010 [CHAT]
1018 INFO "Welcome to Battle.net!"
1018 INFO "This server is hosted by AT&T."
1018 INFO "There are currently 7 users in Chat, and 0 users playing 0
games on Battle.net."
1018 INFO "Last logon: Sat Mar 22 6:27 PM"
1019 ERROR "Failed logon attempts since then: 1"
hmmmm
1019 ERROR "There is no one in this channel."
I know this!
1019 ERROR "There is no one in this channel."
1002 JOIN iago 0010 [CHAT]
1005 TALK iago 0010 "Moooo."
1005 TALK iago 0010 ":)"
Follow me to Backstage.
1005 TALK iago 0010 "Okay."
/join Backstage
1007 CHANNEL "Backstage"
1001 USER Asylum 0010 [CHAT]
1009 USER Asylum 0002 [CHAT]
1002 JOIN iago 0010 [CHAT]
1023 EMOTE iago 0010 "flexes."
1005 TALK iago 0010 "Afk"
/who asdf
1018 INFO "Users in channel asdf:"
1018 INFO "[SKYWING], Skywing#1"
1018 INFO "Skywing#2, Skywing#3"
1018 INFO "Skywing#4"
Same.
2000 NULL
2000 NULL
2000 NULL
2000 NULL
2000 NULL
1009 USER Asylum 0001 [CHAT]
/admins
1018 INFO "Currently logged on administrators: Asylum"
1006 INFO "Asylum as entered the /shutdown command."
1006 INFO "Server will shut down in 60 seconds (7 connections remaining)."

Edit: It may have been 1006 ADMIN "Message."