added icon and fixed windows hostname resolution

This commit is contained in:
Aaron Blakely 2024-03-08 03:18:36 -06:00
parent a9ce4edbb5
commit 222d533236
11 changed files with 49 additions and 8 deletions

BIN
resource.h Executable file

Binary file not shown.

BIN
resources/xbot.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
resources/xbot.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -71,6 +71,7 @@ void add_user_to_channel(char *user, char *host, char *chan)
{
int i;
struct user *u, *uc;
char buf[512];
#ifdef _WIN32
BOOL is_op, is_voice, is_halfop, is_owner, is_admin;
@ -78,13 +79,12 @@ void add_user_to_channel(char *user, char *host, char *chan)
bool is_op, is_voice, is_halfop, is_owner, is_admin;
#endif
struct irc_conn *bot = get_bot();
is_op = false;
is_voice = false;
is_halfop = false;
is_owner = false;
is_admin = false;
struct irc_conn *bot = get_bot();
char buf[512];
if (!strcmp(chan, ""))

View File

@ -10,7 +10,6 @@
#include "events.h"
#include "channel.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -22,6 +21,7 @@
#define FDOPEN _fdopen
#define SETBUF setbuf
#else
#include <stdbool.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
@ -33,8 +33,13 @@
void irc_connect(struct irc_conn *bot)
{
#ifdef _WIN32
char titlebuf[256];
WSADATA wsaData;
struct sockaddr_in server;
struct hostent *host;
sprintf(titlebuf, "xbot [connecting]: %s:%s", bot->host, bot->port);
SetConsoleTitle(titlebuf);
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
eprint("WSAStartup failed.\n");
@ -55,6 +60,22 @@ void irc_connect(struct irc_conn *bot)
server.sin_addr.s_addr = inet_addr(bot->host);
server.sin_port = htons(atoi(bot->port));
// resolve hostname
if (server.sin_addr.s_addr == INADDR_NONE)
{
host = gethostbyname(bot->host);
if (host == NULL)
{
eprint("Error resolving hostname: %d\n", WSAGetLastError());
closesocket(bot->srv_fd);
WSACleanup();
return;
}
memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length);
}
if (connect(bot->srv_fd, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
{
eprint("Failed to connect to IRC server: %d\n", WSAGetLastError());
@ -64,6 +85,9 @@ void irc_connect(struct irc_conn *bot)
return;
}
sprintf(titlebuf, "xbot [connected]: %s:%s", bot->host, bot->port);
SetConsoleTitle(titlebuf);
#else
int srv_fd;
struct addrinfo hints;

View File

@ -20,6 +20,7 @@
#include "timers.h"
#ifdef _WIN32
#include "resource.h"
#include <winsock2.h>
#else
#include <sys/select.h>
@ -40,6 +41,14 @@ int main()
char *p;
int bytesRecv;
#ifdef _WIN32
HICON hIcon;
hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
SendMessage(GetConsoleWindow(), WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
SetConsoleTitle("xbot [starting]");
#endif
bot.in = calloc(INBUF_SIZE, sizeof(char));
bot.out = calloc(OUTBUF_SIZE, sizeof(char));

View File

@ -1,10 +1,10 @@
#include "timers.h"
#include "util.h"
#include "irc.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "timers.h"
#include "util.h"
#include "irc.h"
struct timers *timers;
int delete_queue[512];

BIN
xbot.aps Executable file

Binary file not shown.

View File

@ -15,7 +15,7 @@ bot:
server:
{
host = "10.0.0.103";
host = "memphis.ephasic.org";
port = "6667";
};

BIN
xbot.rc Executable file

Binary file not shown.

View File

@ -62,7 +62,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>lib;include\libconfig-1.7.3\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;lib;include\libconfig-1.7.3\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;MY_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -111,6 +111,7 @@
<ClInclude Include="lib\module.h" />
<ClInclude Include="lib\timers.h" />
<ClInclude Include="lib\util.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\channel.c" />
@ -123,6 +124,13 @@
<ClCompile Include="src\timers.c" />
<ClCompile Include="src\util.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="xbot.rc" />
</ItemGroup>
<ItemGroup>
<None Include="resources\xbot.ico" />
<None Include="resources\xbot.png" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>