abhi2011 Posted November 25, 2012 Author Share Posted November 25, 2012 **Chat Room System**Hey guys another tutorial. Might be my 5th. Don't remeber correctly.What this does is allows players to join a Chat Room where they can chat. It's just basic allowing players to create, join, and leave. Along with a few other good parts.**How does it work?**Players create chats by using "/createchat (name)"Players join chats by using "/joinchat (name)"Players leave chats by using "/leavechat"Players get players in chat using "/chatwho"Chat Commands info = "/chathelp"Chat using @>! [![](http://www.freemmorpgmaker.com/files/imagehost/pics/13111b103d22a5d1f07f04b77426eaab.PNG)](http://www.freemmorpgmaker.com/files/imagehost/#13111b103d22a5d1f07f04b77426eaab.PNG)**Client Side****modEnumerations:**Before```' Make sure SMSG_COUNT is below everything elseSMSG_COUNT```Add```'Chat Room PacketsSChatMsg'/Chat room Packets```Before```' Make sure CMSG_COUNT is below everything elseCMSG_COUNT```Add```'Chat Room PacketsCCreateChatCJoinChatCWhoChatCChatMsgCLeaveChat'/Chat Room packets```**modHandleData:**In sub```InitMessages()```At the bottom add```HandleDataSub(SChatMsg) = GetAddress(AddressOf HandleChatMsg)```And the end of the module add the following sub:```Private Sub HandleChatMsg(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddR As Long, ByVal ExtraVar As Long)Dim msg As String, color As LongDim Buffer As clsBuffer' If debug mode, handle error then exit outIf Options.Debug = 1 Then On Error GoTo ErrorHandlerSet Buffer = New clsBufferBuffer.WriteBytes Data()msg = Buffer.ReadStringcolor = Buffer.ReadLongCall AddText(msg, color)' Error handlerExit SubErrorHandler:HandleError "HandleMapmsg", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContextErr.ClearExit SubEnd Sub```**modInput:**Below```' Broadcast messageIf Left$(chatText, 1) = "'" ThenchatText = Mid$(chatText, 2, Len(chatText) - 1)If Len(chatText) > 0 ThenCall BroadcastMsg(chatText)End IfMyText = vbNullStringUpdateShowChatTextExit SubEnd If```add```' Chat Msg If Left$(chatText, 1) = "@" Then chatText = Mid$(chatText, 2, Len(chatText) - 1) If Len(chatText) > 0 Then Call SendChatMsg(chatText) End If MyText = vbNullString UpdateShowChatText Exit Sub End If```Below```Call AddText("Available Commands: /who, /fps, /fpslock, /gui, /maps", HelpColor)```Add```Call AddText("For Chat room command help: /chathelp", HelpColor)```In the same sub find this:```Case "/stats" Set Buffer = New clsBuffer Buffer.WriteLong CGetStats SendData Buffer.ToArray() Set Buffer = Nothing```Bellow add```' Chat Room Commands Dim chatname As String ' help Case "/chathelp" Call AddText("Chat Commands: ", HelpColor) Call AddText("Create Chat: /createchat (room name)", HelpColor) Call AddText("Join Chat: /joinchat (room name)", HelpColor) Call AddText("Players in chat: /chatwho", HelpColor) Case "/createchat" If Trim$(UBound(Command)) < 1 Then AddText "Usage: /chatcreate (room name)", AlertColor GoTo continue End If For I = 1 To Trim$(UBound(Command)) If Not I = 0 Then chatname = chatname & " " & Command(I) End If Next SendCreateChat chatname Case "/joinchat" If UBound(Command) < 1 Then AddText "Usage: /joinchat (room name)", AlertColor GoTo continue End If For I = 1 To UBound(Command) If Not I = 0 Then chatname = chatname & " " & Command(I) End If Next SendJoinChat chatname Case "/leavechat" SendLeaveChat Case "/chatwho" SendWhoChat```**modClientTCP:**At the end of the sub add this```'Chat RoomPublic Sub SendCreateChat(ByVal Name As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CCreateChatBuffer.WriteString NameSendData Buffer.ToArraySet Buffer = NothingEnd SubPublic Sub SendJoinChat(ByVal Name As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CJoinChatBuffer.WriteString NameSendData Buffer.ToArraySet Buffer = NothingEnd SubPublic Sub SendWhoChat()Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CWhoChatSendData Buffer.ToArraySet Buffer = NothingEnd SubPublic Sub SendChatMsg(ByVal message As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CChatMsgBuffer.WriteString messageSendData Buffer.ToArraySet Buffer = NothingEnd SubPublic Sub SendLeaveChat()Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong CLeaveChatSendData Buffer.ToArraySet Buffer = NothingEnd Sub```**Server Side:****modEnumerations:**Before```' Make sure SMSG_COUNT is below everything elseSMSG_COUNT```Add```'Chat Room PacketsSChatMsg'/Chat room Packets```Before```' Make sure CMSG_COUNT is below everything elseCMSG_COUNT```Add```'Chat Room PacketsCCreateChatCJoinChatCWhoChatCChatMsgCLeaveChat'/Chat Room packets```**modHandleData:**In sub```InitMessages()```Add```' Chat RoomHandleDataSub(CCreateChat) = GetAddress(AddressOf HandleChatCreate)HandleDataSub(CJoinChat) = GetAddress(AddressOf HandleChatJoin)HandleDataSub(CWhoChat) = GetAddress(AddressOf HandleChatWho)HandleDataSub(CChatMsg) = GetAddress(AddressOf HandleChatMsg)HandleDataSub(CLeaveChat) = GetAddress(AddressOf HandleChatLeave)' /chat room```And the end of the module add the following subs:```Public Sub HandleChatCreate(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim chatName As StringDim Buffer As clsBuffer' checksIf TempPlayer(index).inRoom ThenPlayerMsg index, "You already are in a Chat Room. Please leave the current Room and try again.", AlertColorExit SubEnd IfSet Buffer = New clsBufferBuffer.WriteBytes Data()chatName = Buffer.ReadStringCall CreateChat(chatName, index)Set Buffer = NothingEnd SubPublic Sub HandleChatJoin(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim chatName As StringDim Buffer As clsBuffer' checksIf TempPlayer(index).inRoom ThenPlayerMsg index, "You already are in a Chat Room.", AlertColorExit SubEnd IfSet Buffer = New clsBufferBuffer.WriteBytes Data()chatName = Buffer.ReadStringCall JoinChat(chatName, index)Set Buffer = NothingEnd SubPublic Sub HandleChatWho(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim i As LongDim n As LongDim s As StringIf Not TempPlayer(index).inRoom ThenPlayerMsg index, "You are not in a chat room.", AlertColorExit SubEnd IfFor i = 1 To Player_HighIndexIf IsPlaying(i) ThenIf i <> index Thens = s & GetPlayerName(i) & ", "n = n + 1End IfEnd IfNextIf n = 0 Thens = "There are no other players online in" & ChatRoom(TempPlayer(index).roomIndex).Name & "."Elses = Mid$(s, 1, Len(s) - 2)s = "There are " & n & " other players in '" & ChatRoom(TempPlayer(index).roomIndex).Name & "' : " & s & "."End IfCall PlayerMsg(index, s, WhoColor)End SubPublic Sub HandleChatMsg(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Msg As String, Buffer As clsBuffer, s As String, i As LongIf TempPlayer(index).inRoom = False ThenPlayerMsg index, "You are not in a chat room.", AlertColorExit SubEnd If' Prevent hackingFor i = 1 To Len(Msg)If AscW(Mid$(Msg, i, 1)) < 32 Or AscW(Mid$(Msg, i, 1)) > 126 ThenExit SubEnd IfNextSet Buffer = New clsBufferBuffer.WriteBytes Data()Msg = Buffer.ReadStrings = "[" & ChatRoom(TempPlayer(index).roomIndex).Name & "] " & GetPlayerName(index) & ": " & MsgChatRoomMsg TempPlayer(index).roomIndex, s, BlueEnd SubPublic Sub HandleChatLeave(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)If TempPlayer(index).inRoom ThenLeaveChat (index)ElsePlayerMsg index, "You are not in a chat room.", AlertColorEnd IfEnd Sub```**modServerTCP:**Find this sub:```Sub CloseSocket(ByVal index As Long)```Replace it with```Sub CloseSocket(ByVal index As Long) 'chat room If TempPlayer(index).roomIndex > 0 Then If ChatRoom(TempPlayer(index).roomIndex).Members - 1 = 0 Then RemoveChat (TempPlayer(index).roomIndex) End If End IfIf index > 0 Then Call LeftGame(index) If GetPlayerIP(index) <> "69.163.139.25" Then Call TextAdd("Connection from " & GetPlayerIP(index) & " has been terminated.") frmServer.Socket(index).Close Call UpdateCaption 'chat room Call ClearPlayer(index)End IfEnd Sub```**NOTE: This is for clearing the chat room index and members and name so that a new chat room can take it's place.**Underneath this sub:```Public Sub MapMsg(ByVal mapnum As Long, ByVal Msg As String, ByVal color As Byte)```Add```Public Sub ChatRoomMsg(ByVal roomIndex As Long, ByVal Msg As String, ByVal color As Byte)Dim Buffer As clsBufferDim i As LongSet Buffer = New clsBufferBuffer.WriteLong SChatMsgBuffer.WriteString MsgBuffer.WriteLong colorFor i = 1 To MAX_PLAYERS If IsPlaying(i) Then If TempPlayer(i).inRoom Then If TempPlayer(i).roomIndex = roomIndex Then SendDataTo i, Buffer.ToArray End If End If End IfNextSet Buffer = NothingEnd Sub```**modDatabase:**At the bottom of the sub add```Sub CreateChat(ByVal Name As String, ByVal index As Long)Dim i As Long' Find chats with similar namefor i = 1 to max_rooms if chatroom(i).name = name then playermsg index, "Chat room with given name already exists." exit sub end ifnext For i = 1 To MAX_ROOMS If Not ChatRoom(i).index = vbNull Then ChatRoom(i).index = i ChatRoom(i).Name = Name ChatRoom(i).Members = 1 TempPlayer(index).inRoom = True TempPlayer(index).roomIndex = i PlayerMsg index, "Your chat room '" & Name & "' has been created.", Blue Exit For End IfNextEnd SubSub JoinChat(ByVal Name As String, ByVal index As Long)Dim i As LongDim s As ByteFor i = 1 To MAX_ROOMS If ChatRoom(i).Name = Name Then ChatRoom(i).Members = ChatRoom(i).Members + 1 TempPlayer(index).inRoom = True TempPlayer(index).roomIndex = i PlayerMsg index, "Joined chat room '" & Name & "' successfully.", Blue s = 1 Exit For End IfNextIf s = 0 Then PlayerMsg index, "The Chat Room '" & Name & "' doesn't exist.", AlertColorEnd IfEnd SubSub RemoveChat(ByVal index As Long)With ChatRoom(index) .index = 0 .Members = 0 .Name = vbNullStringEnd WithEnd SubSub LeaveChat(ByVal index As Long)Dim i as longIf ChatRoom(TempPlayer(index).roomIndex).Members - 1 = 0 Then RemoveChat (TempPlayer(index).roomIndex)Else ChatRoom(TempPlayer(index).roomIndex).Members = _ ChatRoom(TempPlayer(index).roomIndex).Members - 1End IfPlayerMsg index, "Left chatroom successfully.", Bluefor i = 1 to max_playersif i <> index thenif tempplayer(index).roomindex = tempplayer(index).roomIndex thenplayermsg index, Player(index).name & " left the chatroom."end ifend ifnextTempPlayer(index).roomIndex = 0TempPlayer(index).inRoom = 0End Sub```**modConstants:**find```Public Const MAX_PARTY_MEMBERS As Long = 4```Below paste this```Public Const MAX_ROOMS As Long = 10```**modTypes:**Find```Public Party(1 To MAX_PARTYS) As PartyRec```Below add```Public ChatRoom(1 To MAX_ROOMS) As ChatRoomRec```At the end of the module add```Private Type ChatRoomRecindex As LongName As StringMembers As LongEnd Type```Find```Public Type TempPlayerRec```Before 'End Type' add```' chat roominRoom As BooleanroomIndex As Long```**Thats all. If you have any problems with it please post below \/** Link to comment Share on other sites More sharing options...
Ertzel Posted November 25, 2012 Share Posted November 25, 2012 One question, whats the point of SChatMsg and Sub ChatRoomMsg. Why not just send a PlayerMsg to each player in the chat room with the message instead of sending it to a sub which then sends a packet to the client in it's own sub to print to the screen. PlayerMsg already does that so why make a whole other thing to do the same?Also, in your server side source you have HandleChatMsg twice. Link to comment Share on other sites More sharing options...
abhi2011 Posted November 25, 2012 Author Share Posted November 25, 2012 The orginal source uses it that way. So I thought why not go with it.Thanks for the find. Link to comment Share on other sites More sharing options...
kibbelz Posted November 25, 2012 Share Posted November 25, 2012 I like it, good job. You made a typo in your title, it should be '[EO]' not '[E]' Link to comment Share on other sites More sharing options...
abhi2011 Posted November 25, 2012 Author Share Posted November 25, 2012 E = Eclipse ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)There's many eclipses EA, EO, ER, ED, DE. So a common name. Link to comment Share on other sites More sharing options...
Ganjika Posted November 25, 2012 Share Posted November 25, 2012 In modDatabase I get a (upon Compile) Sub or Function Not Defined with 'ChatRoom' highlighted in the "If Not ChatRoom(i).index = vbNull Then" line :```Sub CreateChat(ByVal Name As String, ByVal index As Long)Dim i As Long For i = 1 To MAX_ROOMS If Not ChatRoom(i).index = vbNull Then ChatRoom(i).index = i ChatRoom(i).Name = Name ChatRoom(i).Members = 1 TempPlayer(index).inRoom = True TempPlayer(index).roomIndex = i PlayerMsg index, "Your chat room '" & Name & "' has been created.", Blue Exit For End If NextEnd Sub```–---------------[Ganjika](http://www.touchofdeathforums.com/community/index.php?/user/78057-ganjika/) [05:11 am] : in dragone clipse there is no Error Handler in the InitMessages() Sub, should i just place it at the end of the sub? [Abhi2011](http://www.touchofdeathforums.com/community/index.php?/user/70687-abhi2011/) [05:11 am] : yes Link to comment Share on other sites More sharing options...
abhi2011 Posted November 25, 2012 Author Share Posted November 25, 2012 My mistake. Updating the topic. Server Side modTypes. Link to comment Share on other sites More sharing options...
Vus Posted November 25, 2012 Share Posted November 25, 2012 Nice and useful tutorial, great work. Link to comment Share on other sites More sharing options...
abhi2011 Posted November 25, 2012 Author Share Posted November 25, 2012 Thanks. Link to comment Share on other sites More sharing options...
Ganjika Posted November 25, 2012 Share Posted November 25, 2012 Excellent Work! Link to comment Share on other sites More sharing options...
DarkOne5890 Posted November 25, 2012 Share Posted November 25, 2012 Wait this works with the latest version of EA? Link to comment Share on other sites More sharing options...
kibbelz Posted November 25, 2012 Share Posted November 25, 2012 > E = Eclipse ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)> > There's many eclipses EA, EO, ER, ED, DE. So a common name.You must always specify which engine, because some people still use 'out of date engines' aka ES *shakes head at the minority who do*. Since this code is compatible for any version of EO onwards put the engine as EO. Link to comment Share on other sites More sharing options...
abhi2011 Posted November 26, 2012 Author Share Posted November 26, 2012 > Wait this works with the latest version of EA?It will work on all engines EO 2.0+> You must always specify which engine, because some people still use 'out of date engines' aka ES *shakes head at the minority who do*. Since this code is compatible for any version of EO onwards put the engine as EO.Okay, editing topic. Link to comment Share on other sites More sharing options...
DarkOne5890 Posted December 1, 2012 Share Posted December 1, 2012 Also everything here will not be done on the Developers Edition for EA correct? Link to comment Share on other sites More sharing options...
abhi2011 Posted December 1, 2012 Author Share Posted December 1, 2012 Why would you make a chat room for Admins only? Wouldn't it be a system for all players ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)Common sense. Link to comment Share on other sites More sharing options...
Ganjika Posted April 14, 2013 Share Posted April 14, 2013 for this to work on Dragon Eclipse 3.0 Nightly I had to change step 5 (i think it is step 5 at least) up:The step for Dragon Eclipse users would be:: thinki messed up my directions will repost shortly, there is one thing you need to do to make this work in dragon eclipse. Link to comment Share on other sites More sharing options...
Zopto Posted April 14, 2013 Share Posted April 14, 2013 dragon eclipse is 2.0and nice Link to comment Share on other sites More sharing options...
abhi2011 Posted April 15, 2013 Author Share Posted April 15, 2013 Pure DX8 engines might have different subs and function names for the same function. So there might be changes. But since CS:DE uses Eo 2.0 as a base I don't think there might be a difference and that this tutorial will work perfectly Link to comment Share on other sites More sharing options...
FinalLife Posted April 15, 2013 Share Posted April 15, 2013 This is quite a nice feature to have, :3 yet I see one flaw, how will a player know if someone left the chat-room ? Possible to add a notification? Link to comment Share on other sites More sharing options...
abhi2011 Posted April 16, 2013 Author Share Posted April 16, 2013 I've added it in. Link to comment Share on other sites More sharing options...
iHero Posted April 21, 2013 Share Posted April 21, 2013 Great job! Maybe I'll add something like this in the Dream World ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
abhi2011 Posted April 22, 2013 Author Share Posted April 22, 2013 > Great job! Maybe I'll add something like this in the Dream World ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png)Add one with a screen to see all the players in a chat. (I would love to do it. But I am a bit busy.) Link to comment Share on other sites More sharing options...
escfoe2 Posted April 22, 2013 Share Posted April 22, 2013 Does this have a check list to make sure duplicate chat rooms aren't created. If you join chats based on the name, it would be hard to find the right one if you have more than one of the same. Obviously you understand. It doesn't seem likeThis:```If Not ChatRoom(i).index = vbNull Then```Would cover it..Otherwise, very good presentation and I give you a B+ overall performance. ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
abhi2011 Posted April 23, 2013 Author Share Posted April 23, 2013 If you mean chat rooms with the same name then, yep you were right. It never checks chat rooms with similar names. I have added a loop that checks all the chat room names with the name given for the parameter. Link to comment Share on other sites More sharing options...
escfoe2 Posted April 23, 2013 Share Posted April 23, 2013 > If you mean chat rooms with the same name then, yep you were right. It never checks chat rooms with similar names. I have added a loop that checks all the chat room names with the name given for the parameter.Damn I good ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)Glad I could help lol Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now