Skip to content

Commit 846da33

Browse files
committed
fixed debugTools
1 parent 32d0d4a commit 846da33

File tree

7 files changed

+96
-425
lines changed

7 files changed

+96
-425
lines changed

FBIDE/IDE/history.ini

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
file1=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\AuClient.bi
2-
file2=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\7 - Working Indev Clean Glitchy\\2\\client99v72.bas
3-
file3=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\8 - Indev\\wikiperlin.bas
4-
file4=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\netcodes.bi
5-
file5=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\7 - Working Indev Clean Glitchy\\2\\server99v72.bas
6-
file6=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\main.bas
7-
file7=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\5 - Unfinished Clean\\Server99v2.bas
8-
file8=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\3\\7 - FreeBasic Network\\server.bas
9-
file9=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\5\\8 - Network Functions\\stiits.bas
1+
file1=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\v3\\main_server3.bas
2+
file2=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\AuClient.bi
3+
file3=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\7 - Working Indev Clean Glitchy\\2\\client99v72.bas
4+
file4=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\8 - Indev\\wikiperlin.bas
5+
file5=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\netcodes.bi
6+
file6=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\7 - Working Indev Clean Glitchy\\2\\server99v72.bas
7+
file7=C:\\Users\\Auios\\Documents\\GitHub\\Empire-of-Tiles\\Network\\main.bas
8+
file8=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\Old\\Networking\\4 - 99\\5 - Unfinished Clean\\Server99v2.bas
9+
file9=C:\\Users\\Auios\\Documents\\GitHub\\FreeBasic_Stuff\\3\\7 - FreeBasic Network\\server.bas

FBIDE/IDE/prefs_win32.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[paths]
44
; Please note that all paths must be set with double slashes! e.g c:\\mydir\\myfile.txt
5-
fbc=C:\\AuFreeBasic\\FreeBasic\\pre-fbc.exe
5+
fbc=D:\\AuFreeBasic\\FreeBasic\\pre-fbc.exe
66
syntax=fbfull.lng
77
theme=classic
88
helpfile=FB-manual-1.04.0.chm
@@ -47,7 +47,7 @@ floatbars=1
4747
winx=960
4848
winy=0
4949
winw=960
50-
winh=1040
50+
winh=1036
5151

5252
;this says whether or not the splash screen is displayed
5353
splashscreen=1

FreeBasic/inc/DebugTools.bi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
#include "crt.bi"
44

5-
declare function db (s as string) as string
6-
function db(s as string) as string
5+
sub db(s as string)
76
var smsg = s & !"\n"
87
printf(smsg)
9-
return smsg
10-
end function
8+
end sub
119

1210
sub dbBar()
1311
printf(!"------------------\n")
12+
end sub
13+
14+
sub dbError(s as string)
15+
printf(s & !"\n")
16+
sleep()
1417
end sub

FreeBasic/inc/netwrapper.bi

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
'//
66
'// Made by Johannes Pihl (Jattenalle)
77

8+
#pragma once
9+
810
#include "debugTools.bi"
911

1012
#ifdef __FB_WIN32__
11-
#include once "win/winsock.bi"
13+
#include once "win/winsock2.bi"
1214
#endif
1315

1416
#define S_RECV 0
@@ -27,7 +29,7 @@ TIMEOUT.tv_sec=0
2729
TIMEOUT.tv_usec=0
2830

2931
dim shared as WSADATA wsaData
30-
32+
dim shared as sockaddr_in null_addr_in
3133

3234
type _CONNECTION_
3335
socket as SOCKET
@@ -48,6 +50,51 @@ function nw_start() as long
4850
return WSAStartup( MAKEWORD( 1, 1 ), @wsaData )
4951
end function
5052

53+
'function nw_Start( byval verhigh as integer = 1, byval verlow as integer = 1 ) as boolean
54+
' dim wsaData as WSAData
55+
' if( WSAStartup( MAKEWORD( verhigh, verlow ), @wsaData ) <> 0 ) then
56+
' return FALSE
57+
' end if
58+
' if( wsaData.wVersion <> MAKEWORD( verhigh, verlow ) ) then
59+
' WSACleanup( )
60+
' return FALSE
61+
' end if
62+
' function = TRUE
63+
'end function
64+
65+
function nw_Shutdown( ) as integer
66+
function = WSACleanup( )
67+
end function
68+
69+
'Listen
70+
sub nw_listen(cc as _CONNECTION_, port as integer)
71+
db("Creating listener socket...")
72+
with cc
73+
.socket_in.sin_port = htons(port)
74+
'cc->socket_in.sin_port = port
75+
.socket_in.sin_family = AF_INET
76+
.socket_in.sin_addr.S_addr = INADDR_ANY
77+
.socket=opensocket(AF_INET, SOCK_STREAM, 0)
78+
if .socket=INVALID_SOCKET then
79+
color 12: db("ERROR: Unable to open server socket."): color 7
80+
sleep
81+
end
82+
end if
83+
if bind(cc.socket, cptr(sockaddr ptr, @.socket_in), len(.socket_in)) then
84+
color 12: db("ERROR: Unable to bind listening socket. "& WSAGetLastError()): color 7
85+
sleep
86+
end
87+
end if
88+
'listen(.socket, SOMAXCONN)
89+
if listen(.socket, 8) then
90+
color 12: db("ERROR: Unable to initiate listen. "& WSAGetLastError()): color 7
91+
sleep
92+
end
93+
end if
94+
end with
95+
db("Created!")
96+
end sub
97+
5198
'// Takes hostname, resolves to packed IP (integer)
5299
function nw_resolveHost( hostname as string ) as integer
53100
dim ia as in_addr
@@ -77,7 +124,6 @@ end function
77124
'// Returns number of bytes received if no error, returns error code on error. Error code must be < 0
78125
function nw_recv(byval cc as _CONNECTION_, byval buffer as any ptr, byval bufferlen as integer=RECVBUFFLEN) as integer
79126
dim as integer bytes = recv( cc.socket, buffer, bufferlen, 0 )
80-
if bytes < 0 then db("ERROR: nw_ERR"& bytes &" when receiving on socket "& cc.socket &" ["& cc.ip &"]")
81127
return bytes
82128
end function
83129

@@ -109,33 +155,36 @@ function nw_isset(byval cc as _CONNECTION_, byval w as integer) as integer
109155
end function
110156

111157
'// Connect to uri on port using cc, return 0 on success, anything else is an error code
112-
function nw_connect(byval cc as _CONNECTION_ ptr, byval uri as string, byval port as integer) as integer
113-
cc->ip = nw_resolveHost(uri)
114-
cc->socket_in.sin_port = htons( port )
115-
cc->socket_in.sin_family = AF_INET
116-
cc->socket_in.sin_addr.S_addr = cc->ip
117-
cc->socket = opensocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
118-
if cc->socket=INVALID_SOCKET then
119-
db("ERROR: Unable to open socket.")
120-
cc->socket = 0
121-
return -1 '// Error
122-
else
123-
if connect( cc->socket, cast( PSOCKADDR, @cc->socket_in ), len( cc->socket_in )) = SOCKET_ERROR then
124-
dim as ubyte ptr i = cptr(ubyte ptr, @cc->ip)
125-
db("ERROR: "& uri &" ["& i[0] &"."& i[1] &"."& i[2] &"."& i[3] &"] is unreachable")
126-
closesocket( cc->socket )
127-
cc->socket = 0
128-
return -2 '// Error
129-
else
130-
return 0 '// All went well!
131-
end if
132-
end if
158+
function nw_connect(byval cc as _CONNECTION_, byval uri as string, byval port as integer) as integer
159+
with cc
160+
.ip = nw_resolveHost(uri)
161+
.socket_in.sin_port = htons( port )
162+
.socket_in.sin_family = AF_INET
163+
.socket_in.sin_addr.S_addr = .ip
164+
.socket = opensocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
165+
if .socket=INVALID_SOCKET then
166+
db("ERROR: Unable to open socket.")
167+
.socket = 0
168+
return -1 '// Error
169+
else
170+
if connect( .socket, cast( PSOCKADDR, @.socket_in ), len( .socket_in )) = SOCKET_ERROR then
171+
dim as ubyte ptr i = cptr(ubyte ptr, @.ip)
172+
db("ERROR: "& uri &" ["& i[0] &"."& i[1] &"."& i[2] &"."& i[3] &"] is unreachable")
173+
db("Last error: " & WSAGetLastError())
174+
closesocket( .socket )
175+
.socket = 0
176+
return -2 '// Error
177+
else
178+
return 0 '// All went well!
179+
end if
180+
end if
181+
end with
133182
end function
134183

135184
'// Disconnect and clear a socket, must not fail!
136-
function nw_disconnect(byval cc as _CONNECTION_ ptr) as integer
137-
shutdown(cc->socket, SD_BOTH)
138-
closesocket(cc->socket)
139-
cc->socket = 0
185+
function nw_disconnect(byval cc as _CONNECTION_) as integer
186+
shutdown(cc.socket, SD_BOTH)
187+
closesocket(cc.socket)
188+
cc.socket = 0
140189
return TRUE
141190
end function
File renamed without changes.

0 commit comments

Comments
 (0)