Skip to content

Commit

Permalink
moved http
Browse files Browse the repository at this point in the history
  • Loading branch information
stonedDiscord committed Oct 10, 2017
1 parent 68c1cff commit d45999b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 70 deletions.
81 changes: 15 additions & 66 deletions main.pb
Original file line number Diff line number Diff line change
Expand Up @@ -2486,30 +2486,7 @@ Procedure HandleAOCommand(ClientID)
Case "GET"
*usagePointer\type=#WEBBROWSER
RequestedFile$=StringField(StringField(rawreceive$,2," "),1,"?")
Debug "rfile"
Debug RequestedFile$
If RequestedFile$ = "" Or RequestedFile$ = "/"
RequestedFile$ = "index.html"
EndIf

If ReadFile(0,"cbase/"+RequestedFile$)

FileLength = Lof(0)
ContentType$ = MIME(RequestedFile$)
RFileDate=GetFileDate("cbase/"+RequestedFile$,#PB_Date_Modified)
RHeader$="HTTP/1.0 200 OK"+#CRLF$+"Date: "+DayInText(RFileDate)+","+Day(RFileDate)+" "+MonthInText(RFileDate)+" "+FormatDate("%yyyy %hh:%ii:%ss",RFileDate)+" GMT"+#CRLF$+"Content-Type: "+ContentType$+#CRLF$+"Content-Length: "+Str(FileLength)+#CRLF$+#CRLF$
*FileBuffer = AllocateMemory(FileLength+Len(RHeader$)+20)
HLength=PokeS(*FileBuffer,RHeader$)
*BufferOffset = *FileBuffer+HLength
WriteLog(ip$+" requested file "+RequestedFile$,Server)
ReadData(0,*BufferOffset,FileLength)
Debug "headerlength"
Debug HLength
CloseFile(0)
Debug PeekS(*FileBuffer,HLength+FileLength)
SendNetworkData(ClientID,*FileBuffer,HLength+FileLength)
FreeMemory(*FileBuffer)
EndIf
GETrequest(RequestedFile$,ClientID)
CompilerEndIf
Default
WriteLog(rawreceive$,*usagePointer)
Expand Down Expand Up @@ -2557,47 +2534,12 @@ Procedure Network(var)
Debug "wotf"
rawreceive$=PeekS(*Buffer,length)
Debug rawreceive$
If ExpertLog
WriteLog(rawreceive$,Clients())
EndIf
If length>=0
For i = 1 To CountString(rawreceive$,#CRLF$)
headeririda$ = StringField(rawreceive$,i,#CRLF$)
headeririda$ = RemoveString(headeririda$,#CR$)
headeririda$ = RemoveString(headeririda$,#LF$)
If Left(headeririda$,3) = "GET"
Debug "getline"
RequestedFile$=StringField(StringField(headeririda$,2," "),1,"?")
Debug "rfile"
Debug RequestedFile$
If RequestedFile$ = ""
Break
EndIf
cType=#WEBBROWSER
If ReadFile(0,"cbase/"+RequestedFile$)

FileLength = Lof(0)

ContentType$=MIME(RequestedFile$)
RFileDate=GetFileDate("cbase/"+RequestedFile$,#PB_Date_Modified)
RHeader$="HTTP/1.0 200 OK"+#CRLF$+"Date: "+DayInText(RFileDate)+","+Day(RFileDate)+" "+MonthInText(RFileDate)+" "+FormatDate("%yyyy %hh:%ii:%ss",RFileDate)+" GMT"+#CRLF$+"Content-Type: "+ContentType$+#CRLF$+"Content-Length: "+Str(FileLength)+#CRLF$+#CRLF$
*FileBuffer = AllocateMemory(FileLength+Len(RHeader$)+20)
HLength=PokeS(*FileBuffer,RHeader$)
*BufferOffset = *FileBuffer+HLength
WriteLog(ip$+" requested file "+RequestedFile$,Server)
ReadData(0,*BufferOffset,FileLength)
Debug "headerlength"
Debug HLength
CloseFile(0)
Debug PeekS(*FileBuffer,HLength+FileLength)
SendNetworkData(ClientID,*FileBuffer,HLength+FileLength)
FreeMemory(*FileBuffer)
CloseNetworkConnection(ClientID)
send=0
EndIf
ElseIf Left(headeririda$,17) = "Sec-WebSocket-Key"
headeririda$ = StringField(rawreceive$,1,#CRLF$)
wkeypos=FindString(rawreceive$,"Sec-WebSocket-Key")
If wkeypos
cType=#WEBSOCKET
wkey$ = Right(headeririda$,Len(headeririda$) - 19)
wkey$ = Mid(rawreceive$,wkeypos+19,24)
Debug wkey$
rkey$ = SecWebsocketAccept(wkey$)
Debug rkey$
Expand All @@ -2608,9 +2550,16 @@ Procedure Network(var)
vastus$ = vastus$ + "Upgrade: websocket"+ #CRLF$ + #CRLF$
Debug vastus$
send=1
Debug vastus$
SendNetworkString(ClientID,vastus$)
ElseIf Left(rawreceive$,3) = "GET"
Debug "getline"
cType=#WEBBROWSER
RequestedFile$=StringField(StringField(headeririda$,2," "),1,"?")
GETrequest(RequestedFile$,ClientID)
CloseNetworkConnection(ClientID)
send=0
EndIf
Next
EndIf
Else
SendNetworkString(ClientID,"decryptor#"+decryptor$+"#%")
Expand Down Expand Up @@ -2850,7 +2799,7 @@ CompilerEndIf

End
; IDE Options = PureBasic 5.31 (Windows - x86)
; CursorPosition = 1313
; FirstLine = 1265
; CursorPosition = 2535
; FirstLine = 2517
; Folding = ------
; EnableXP
2 changes: 1 addition & 1 deletion poker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BlockINI = 1
ModColor = 0
#only moderators can use this color

MOTD = Welcome, this server is for testing AO2
MOTD = Take that!
#this changes what dolan says. set this to "Take that!" or comment out to disable

LoopMusic = 1
Expand Down
38 changes: 35 additions & 3 deletions server_shared.pb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,38 @@ Procedure RemoveDisconnect(ClientID)
UnlockMutex(ListMutex)
EndProcedure

Procedure GETrequest(requestedFile$,ClientID)
Debug "rfile"
Debug RequestedFile$
If RequestedFile$ = "" Or RequestedFile$ = "/"
RequestedFile$ = "index.html"
EndIf

If ReadFile(0,"cbase/"+RequestedFile$)

FileLength = Lof(0)
ContentType$ = MIME(RequestedFile$)
RFileDate=GetFileDate("cbase/"+RequestedFile$,#PB_Date_Modified)
RHeader$="HTTP/1.0 200 OK"+#CRLF$+"Last-Modified: "+DayInText(RFileDate)+", "+Day(RFileDate)+" "+MonthInText(RFileDate)+" "+FormatDate("%yyyy %hh:%ii:%ss",RFileDate)+" GMT"+#CRLF$+"Content-Type: "+ContentType$+#CRLF$+"Content-Length: "+Str(FileLength)+#CRLF$+"Cache-Control: max-age=2628000, public"+#CRLF$+#CRLF$
*FileBuffer = AllocateMemory(FileLength+Len(RHeader$)+20)
HLength=PokeS(*FileBuffer,RHeader$,#PB_String_NoZero)
*BufferOffset = *FileBuffer+HLength
WriteLog(ip$+" requested file "+RequestedFile$,Server)
ReadData(0,*BufferOffset,FileLength)
Debug "headerlength"
Debug HLength
CloseFile(0)
Debug PeekS(*FileBuffer,HLength+FileLength)
SendNetworkData(ClientID,*FileBuffer,HLength+FileLength)
FreeMemory(*FileBuffer)
Else
RHeader$="HTTP/1.0 404 NOT FOUND"+#CRLF$+#CRLF$
SendNetworkString(ClientID,RHeader$)
EndIf
Debug "not funny"

EndProcedure

Procedure SendString(ClientID,message$)
Select Clients()\type
Case #WEBSOCKET
Expand Down Expand Up @@ -491,7 +523,7 @@ Procedure SendChatMessage(*ntmes.ChatMessage,*seUser.Client)

Select *ntmes\position
Case "def"
Case "hld"
Case "hld"
vpos=1;left
Case "pro"
vpos=2;right
Expand Down Expand Up @@ -581,7 +613,7 @@ Procedure TrackWait(a)
Until LoopMusic=0
EndProcedure
; IDE Options = PureBasic 5.31 (Windows - x86)
; CursorPosition = 518
; FirstLine = 484
; CursorPosition = 435
; FirstLine = 417
; Folding = ------
; EnableXP

0 comments on commit d45999b

Please sign in to comment.