Aug 27, 2014 07:47 AM
(This post was last modified: Aug 27, 2014 07:48 AM by gogglebot.)
Hi there,
After that post by IronByte asking about Chatrooms in Batch, and looking at a couple of the links posted in there I've decided to take one of them and modify it. I've left the original credit in there.
It consists of two batch files currently, one is simple; "ChatDisplay.bat" does what it says on the tin, it displays the chat log, updating every second.
The main batch, (I named it ChatroomMain.bat, for whatever reason my brain came up with at the time, it doesn't particularly matter right now.) is the one that allows for a user to actually add messages to the chat log, clear the log, and exit.
On start up you can set your username, this will mark all your chats. It then outputs %username% has joined from %computername%.
This helps to avoid confusion if someone starts up two of them with different names on the same PC, everyone can see that it's the same one.
When you clear the log (by typing CLS or cls) it copies log.dat to "log-datehere-timehere.old" (in the format DDMMYYYY-HrsMins) and empties log.dat, leaving the message "%username% has cleared the chat log."
Note: I need to add seconds to this to avoid overwrites in the case of a minute not passing between two clears. Any pointers?
Typing either EXIT or exit will send the message "%username% has left the chat."
The batch will stop you sending the same thing twice, in an anti-spam attempt.
To use this with users on a network, you'd need to have a folder on one of the machines or on a server that is shared with all the users, with read\write permissions. You'll then need to set the logloc variable at the top to this folder, above I have left it blank. So it'd likely be \\HOST-NAME\chatroom\
IMPORTANT NOTE REGARDING THE LOCATION:
THE TRAILING '\' IS IMPORTANT! DO NOT INCLUDE ""s AROUND IT, THE CODE DOES THIS ON ITS OWN, INCLUDING THEM YOURSELF WILL BREAK IT.
Note: Avoid using the | pipe character as this has a tenancy to break stuff also.
Note2: Remember if there's no log.dat ChatDisplay will not work until there is one, make sure logloc is correctly set in both files and that log.dat exists.
Screenshots, using this and my old laptop connected on a homegroup network.
Spoiler (Click to View)
I hope someone somewhere finds this useful, Enjoy HF! Please report any issues (and a fix, if you can!)
After that post by IronByte asking about Chatrooms in Batch, and looking at a couple of the links posted in there I've decided to take one of them and modify it. I've left the original credit in there.
It consists of two batch files currently, one is simple; "ChatDisplay.bat" does what it says on the tin, it displays the chat log, updating every second.
Code
@echo off
set logloc=
title Chatroom Display
:display
cls
type %logloc%log.dat
timeout 1 >nul
goto displayThe main batch, (I named it ChatroomMain.bat, for whatever reason my brain came up with at the time, it doesn't particularly matter right now.) is the one that allows for a user to actually add messages to the chat log, clear the log, and exit.
Code
@echo off
rem: Matthew Merchant ScriptingMadness.blogspot.com Improved by gogglebot @ HackForums.net
rem ###### TITLE SCREEN ######
title Batch Chatroom Input
color f0
set logloc=
echo.
echo Welcome to The Batch Chatroom.
echo.
echo Commands:
echo Type CLS to clear the chat log, please avoid excessive use!
echo Type EXIT to quit the chat room, rather than closing the window.
echo.
echo Don't be mean to people!
echo.
set /p username=What is your name?
echo %username% has joined from %computername%. >> "%logloc%log.dat"
title Batch Chatroom Input: %username%
set lastmessage=""
cls
goto CHATLOOP
REM ######
REM ###### CHAT LOOP ######
:CHATLOOP
set /p message=Say:
rem set message checker value
set thismessage="%message%"
rem check for exit
if %thismessage% == "EXIT" echo %username% has left the chat room. >> "%logloc%log.dat"&& exit
if %thismessage% == "exit" echo %username% has left the chat room. >> "%logloc%log.dat"&& exit
rem ------
rem check for clear
if %thismessage% == "CLS" goto clear
if %thismessage% == "cls" goto clear
goto noclear
:clear
for /f "tokens=1,2,3,4 delims=/ " %%a in ('Date /t') do (
set dayw=%%a
set day=%%b
set month=%%c
set year=%%d
)
for /f "tokens=1,2 delims=: " %%a in ('Time /t') do (
set hour=%%a
set mins=%%b
)
copy "%logloc%\log.dat" "%logloc%log-%day%%month%%year%-%hours%%mins%.old"
echo %username% from %computername% has cleared the chat log. > "%logloc%log.dat"
set message=Empty
set lastmessage="Empty"
goto CHATLOOP
rem ------
:noclear
rem check for same message as last time
if %thismessage% == %lastmessage% echo You said that last time!&& goto CHATLOOP
rem if all checks out, go ahead and post this message
echo %username%: %message% >> "%logloc%log.dat"
rem save value for next test
set lastmessage="%message%"
goto CHATLOOP
REM ####END OF CHAT LOOP ####On start up you can set your username, this will mark all your chats. It then outputs %username% has joined from %computername%.
This helps to avoid confusion if someone starts up two of them with different names on the same PC, everyone can see that it's the same one.
When you clear the log (by typing CLS or cls) it copies log.dat to "log-datehere-timehere.old" (in the format DDMMYYYY-HrsMins) and empties log.dat, leaving the message "%username% has cleared the chat log."
Note: I need to add seconds to this to avoid overwrites in the case of a minute not passing between two clears. Any pointers?
Typing either EXIT or exit will send the message "%username% has left the chat."
The batch will stop you sending the same thing twice, in an anti-spam attempt.
To use this with users on a network, you'd need to have a folder on one of the machines or on a server that is shared with all the users, with read\write permissions. You'll then need to set the logloc variable at the top to this folder, above I have left it blank. So it'd likely be \\HOST-NAME\chatroom\
IMPORTANT NOTE REGARDING THE LOCATION:
THE TRAILING '\' IS IMPORTANT! DO NOT INCLUDE ""s AROUND IT, THE CODE DOES THIS ON ITS OWN, INCLUDING THEM YOURSELF WILL BREAK IT.
Note: Avoid using the | pipe character as this has a tenancy to break stuff also.
Note2: Remember if there's no log.dat ChatDisplay will not work until there is one, make sure logloc is correctly set in both files and that log.dat exists.
Screenshots, using this and my old laptop connected on a homegroup network.
Spoiler (Click to View)
I hope someone somewhere finds this useful, Enjoy HF! Please report any issues (and a fix, if you can!)
Keep me fed and alive at Uni:
Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BSI'll draw terrible art in paint.NET for you, on request, in return <3


![[Image: N5HEJPo.jpg?1]](https://i.imgur.com/N5HEJPo.jpg?1)
![[Image: 4UJj770.png?1]](https://i.imgur.com/4UJj770.png?1)

![[Image: New-Signature-v2.png]](https://i.ibb.co/FLQmYqVX/New-Signature-v2.png)
