' function to handle the messages clients send to pounce
' everything here should get it done as fast as possible
' message structure for handling inbound CopyData events is just the header.
' we use a pointer to the actual data for the event.
TYPE FcMessage
Magic AS STRING * 4
fcCmd AS DWORD
fcLength AS DWORD
END TYPE
SUB CopyDataHandler(hWindow AS DWORD, lpData AS DWORD)
LOCAL lpCopyData AS COPYDATASTRUCT POINTER
LOCAL lpAsciiz AS ASCIIZ POINTER
LOCAL lpBytes AS BYTE POINTER
LOCAL lcData, Work, dWork AS STRING
LOCAL fMessage AS FcMessage
LOCAL lpMessage AS FcMessage POINTER
LOCAL MiDx, cIndex, iResult AS LONG
LOCAL fIndex, dIndex AS LONG
LOCAL Dream AS DREAMSTRUCTURE
LOCAL Furre AS FURRESTRUCTURE
lpCopyData = lpData
lpAsciiz = @lpCopyData.lpData
lpBytes = @lpCopyData.lpData
lpMessage = @lpCopyData.lpData
fMessage = @lpMessage
Work = ""
IF @lpMessage.Magic = "fc10" THEN
lcData = ""
' the data for Furcadia usually follows the header,
' we take everything from position 12 and up as the message
FOR MiDx = 12 TO @lpCopyData.cbData - 1
lcData = lcData & CHR$(@lpBytes[MiDx])
NEXT MiDx
' the commands are constants, see Globals for actual numbers.
SELECT CASE fMessage.fcCmd
CASE %SpotOnline
' client notification of registered furre online
' in theory, this happens when a name has been passed to the client
' already as being a listed name, inconsistent event.
fIndex = Furres.FurreIndex(lcData)
' if we get back an index, we have a listed furre
IF (fIndex <> 0) THEN
Work = "("& FORMAT$(fMessage.fcCmd) &") "& lcData _
&" [Client Spotting Online]"
Work = Work &"="& FORMAT$(fIndex)
fIndex = (fIndex AND %IndexMask)
' behavior below does not match Timo's implementation.
' need to send an Unlisted Online to the clients.
' do not do that here due to client depending on this
' returning before it processes more info
IF (Furres.OnlineStatus(fIndex) = 0) THEN
Furres.OnlineStatus(fIndex) = 1
PostMessage hWinMain, %WM_COMMAND, _
%UM_RELOADTREELIST, 0
' implementation is different from dream visit
' we have the index in this case.
' see WndProc for implementation
PostMessage hWinMain, %WM_COMMAND, _
%UM_POSTCLIENTSPOTONLINE, fIndex
END IF
END IF
CASE %UpdateWhisperInfo ' make whisper window
' REPLACE " " WITH " [-] " IN lcData
Work = "("& FORMAT$(fMessage.fcCmd) &") [Whisper] "& lcData
' is for updating which furre was whispered last with who
dWork = PARSE$(lcData, " ", 2)
lcData = PARSE$(lcData, " ", 1)
Furres.FurreWhispers(lcData, dWork)
CASE %ClientLogsIn ' client logged in
cIndex = hClients.AddClient(hWindow, lcData)
iResult = hWinMenu.AddMenuItem(hGoWhisper, lcData, _
%IDM_ClientList + cIndex)
CASE %ClientLogsOut ' client logged out
cIndex = hClients.RemoveClient(hWindow)
iResult = hWinMenu.DeleteMenuItem(%IDM_ClientList + cIndex)
CASE %FurreWhispers ' furre whispers
'THIS is the noise maker
Work = "("& FORMAT$(fMessage.fcCmd) &") [Whisper] "& lcData
IF (ISTRUE Furres.FurreWhispers(lcData, "")) THEN
' if the method returns true, name was NOT in the list
' create the treenode in bold ?
' see FurreOnlineManager FurreWhispers for handling.
PostMessage hWinMain, %WM_COMMAND, _
%UM_RELOADTREELIST, 0
END IF
' we check first if global sound is on,
' then if furre sound is on.
IF (ISTRUE ShowSounds) _
AND (ISTRUE Furres.WhisperSound(lcData, %FALSE)) THEN
THREAD CREATE SoundPlayer(%PlayWhisper) TO hPlaySound
END IF
CASE %AddFurreToPounce ' client sez to add name to pounce
Work = "("& FORMAT$(fMessage.fcCmd) &") [Add To List] "& lcData
' potential for making Add To Pounce Window Edit
fIndex = Furres.FurreIndex(lcData)
IF fIndex = 0 THEN
fIndex = Furres.AddNewFurre(lcData, "", "")
END IF
' make them a member of the list
fIndex = fIndex AND %IndexMask
IF (Furres.Unknown(fIndex) > 0) THEN
IF (ISFALSE Furres.ConvertUnknown(fIndex)) THEN _
PostMessage hWinMain, %WM_COMMAND, _
%UM_RELOADTREELIST, 0
END IF
CASE %FurreSpeaks ' someone speaks
' specifically for making noise when someone in the list speaks
' this should only online someone who is in the list
' ? AND the client has been notified they are offline ?
fIndex = Furres.FurreIndex(lcData)
IF (fIndex <> 0) THEN
' mask out the speaking check to reduce debug info
' Work = "("& FORMAT$(fMessage.fcCmd) &") _
' "& lcData &" [Speaks]"
' Work = Work &"="& FORMAT$(fIndex)
fIndex = (fIndex AND %IndexMask)
IF (ISTRUE ShowSounds) _
AND (ISTRUE Furres.WhisperSound(lcData, %TRUE)) THEN
THREAD CREATE SoundPlayer(%PlayTalk) TO hPlaySound
END IF
IF (Furres.OnlineStatus(fIndex) = 0) THEN
Furres.OnlineStatus(fIndex) = 1
PostMessage hWinMain, %WM_COMMAND, _
%UM_RELOADTREELIST, 0
END IF
END IF
CASE %RightClickWhisper ' add temp name to pounce
Work = "("& FORMAT$(fMessage.fcCmd) &") "& lcData _
&" [Right Click Whisper Action]"
IF (ISTRUE Furres.FurreWhispers(lcData, "")) THEN
' if the method returns true, name was NOT in the list
PostMessage hWinMain, %WM_COMMAND, _
%UM_RELOADTREELIST, 0
END IF
CASE %AddDreamToPounce ' add dream to pounce
' this can only work if the calling client is IN the dream
' and the dream has not expired,
' so technically, this should first try conversion
' before entering.
' to prevent lockup errors, need to winproc message this
' if the dream already exists, EDIT? provide supression?
IF (hAddEdit = 0) THEN
Work = "("& FORMAT$(fMessage.fcCmd) _
&") [Add To List] "& lcData
dIndex = Dreams.EnteredDream(lcData)
IF (dIndex > 0) THEN
PostMessage hWinMain, _
%WM_COMMAND, %UM_RELOADTREELIST, 0
END IF
Work = Work &" = Dreams.Total("& FORMAT$(dIndex) &") "
dIndex = Dreams.DreamIndex(lcData)
Work = Work &" = Dreams.Index("& _
FORMAT$(dIndex AND %IndexMask) _
&"-"& FORMAT$(dIndex) &")"
' we post a message to WinProc to cause the dialog to show
PostMessage hWinMain, %WM_COMMAND, _
%UM_ADDDREAMTOLIST, dIndex
ELSE
Work = "Fail, dialog already open"
END IF
CASE %AddVisitedDream ' add temp dream to pounce
Work = "("& FORMAT$(fMessage.fcCmd) &") "& lcData _
&" [Temp Dream Added]"
' if the class method returns Zero
' dream is already in the list
dIndex = Dreams.EnteredDream(lcData)
' we also need to send a message to the clients that
' this dream was added.
' proper implementation requires that to be done as a
' PostMessage call to WinProc to prevent client lockup.
' note that if the dream is already in the list, no message.
' the message is sent by the Dream Online Class
IF (dIndex > 0) THEN
PostMessage hWinMain, _
%WM_COMMAND, %UM_RELOADTREELIST, 0
END IF
Work = Work &" = Dreams.Total("& FORMAT$(dIndex) &")"
CASE ELSE
' if we get here, then someone either put in a new message,
' or there's a message we managed to never get when decoding them.
Work = "Undecoded Command: "& FORMAT$(fMessage.fcCmd) _
&"("& HEX$(fMessage.fcCmd, 8) &")" _
&" Length:"& FORMAT$(fMessage.fcLength) _
&" Data:"& lcData
END SELECT
IF LEN(Work) > 0 THEN
Work = TIME$ &":"& hClients.ClientNameByHandle(hWindow) &"-"& Work
#DEBUG PRINT Work
END IF
END IF
END SUB
GeSHi parsed in 0.946253061295 seconds.
|