noobtuts

noobchat - The ultimate Chat Solution

noobchat - Unity Multiplayer Chat

Introduction

Multiplayer games are hard, especially for Indie game developers. noobchat is the quick and easy solution if you want to add a chat to your multiplayer game: a complete Prefab that can be dragged into the Scene - ready to go immediately.

Making a decent Chat requires a whole lot of complicated features like whispering, public chat, groups, authentication, reconnecting, thread safety and passwords. Especially as indie game developers, we don't really want to spend one or two months of our time, just so that the chat works properly (which by the way is how long it took us to make noobchat).

The good news is that the IRC Protocol was already around for more than 20 years now, so the smartest solution is to implement our own IRC Client in Unity that can work with an already existing IRC server (which saves us from having to create a complicated chatserver with features like channels, swearword filters, anti-flood, anti-spam, concurrency and of course long nights of testing).

noobchat is the final multiplayer chat solution that uses the established IRC Protocol to make MMORPG, MOBA, FPS, RTS and just about any other game's chat possible. We will provide extensive usage scenarios further down this page.

Unity Webplayer Demo: click here

Features

Let's take a look at noobchat's features:

Usage Guide

Let's take a look at how we can setup our chat system.

When doing Networking in Unity, it's always important to go to Edit->Project Settings->Player and enable Run In Background:
Unity run in background

This option makes sure that networking won't just freeze and cause timeouts or disconnects when the back is in the background or minimized.

Adding the Prefab to the Scene

As soon as we imported the noobchat package into Unity, we can see a new noobchat folder in the Project Area:
noobchat folder in Project Area

Unity's UI system always requires a Canvas and a EventSystem to be in the Hierarchy, so if you haven't already, simply right click in the Hierarchy and select UI->Canvas and UI->EventSystem:
Canvas and Event System

Now we can drag the ChatPanel from the noobchat/Prefabs folder into the Canvas:
Drag ChatPanel Prefab into Scene

If we select the ChatPanel in the Hierarchy, then we can modify the chat settings in the Inspector:
noobchat in Inspector

By default, the chat already uses a test server that works: irc.gnu.org with port 6665. Random Nick feature makes sure that we don't run into nickname issues when connecting to a public test server.
Note: it's recommended to use your own IRC server and disable the Random Nick feature when using the chat in a real game.

If we press Play then we can already see how noobchat connects to the IRC server:
Chat ingame

Understanding Channels

If we take a closer look at the Inspector, then we can see the channels property:
Test Channel in Inspector

noobchat is basically one chat window for multiple irc channels. We can configure each channel like this:

And that's all. Now we will take a look at different multiplayer games and how we can configure noobchat to support them.

Usage Scenario: MOBA or FPS Game

Let's learn how we can adapt noobchat to a MOBA style game like Dota or a FPS style game like Counter-Strike. The solution is fairly simple.

First of all, we will need one big chatserver to which every player connects to. Simply being connected to it already allows for private messages between the players.

Whisper

So first of all, we would create a whisper channel like this one:
Unity MOBA Chat Whisper Channel

Once connected to the server, it already allows us to whisper just about anyone. For example, we can whisper someone named Bob:
Unity MOBA Chat Whisper Example

And if he replies to us, this is how it looks:
Unity MOBA Chat Whisper reply Example

Team and TeamAll Chats

Alright so as soon as the player joins a game, the gameserver should create three new channels on the IRC Server:

So each player in TeamRed would get two more noobchat channels:
MOBA Team Red

And each player in TeamBlue also gets two more channels:
MOBA Team Blue
Note: obviously we don't want the red player to see the blue channel and vice versa.

So once ingame, a player can send 3 kinds of messages:

hello team!                <- sent to his team
/all hello everyone!       <- sent to both teams
/w Bob hello Bob!          <- sent to player Bob

And here is how it looks ingame:
Unity MOBA Chat ingame

And that's all - perfect chat support without worrying about anything.

Usage Scenario: MMORPG

noobchat works perfectly fine for just about any MMORPG game. A typical MMORPG has a few different chat requirements:

Whisper

So first of all, we would create a whisper channel again:
Unity MMORPG Chat Whisper Channel

Afterwards we can whisper anyone that is connected to the chat server:
Unity MMORPG Chat Whisper Example

Of course, people can also whisper us back:
Unity MMORPG Chat Whisper reply Example

Local Chat

MMORPGs usually offer local chat as the default channel. We will begin by creating the channel:
MMORPG local chat

We used the empty Command so that every message without a command will be sent to local chat.

Here is how we can use it ingame:
MMORPG local chat example message

There is one more thing to keep in mind. Right now, the server would have one local chat channel, which means that everyone on the server could read everyone else's local messages - which is more like a public chat than a local chat. However there is also the option to make a truly local chat, where players would only communicate with players that are in a certain radius around them. The easiest solution to this problem is to divide the gameworld into some kind of grid with several local channels. Think about a town that is it's own local channel like #localMysterytown, and every player in this town will automatically join the #localMysterytown channel and hence only use localchat to communicate with the people in that town.
Note: noobchat allows for dynamic channel joining and leaving by using the Script's ChannelAdd and ChannelRemove functions, which can be used to make a truly local chat possible.

Guild Chat

In a MMORPG game, there would be several different guilds among the players. noobchat supports guilds perfectly fine, because we would simply create one channel for each guild. So for example:

Afterwards we can assign the correct guild channel to each player's noobchat, for example:
MMORPG Guild chat

As we can see in the above picture, we used the Command /g, which means that a player can write a guild message like this:
MMORPG Guild chat example message

Alliance Chat

Some MMORPGs will have alliances, which are always a group of several different guilds. We can support alliance chat just like we did with the guild chat:
MMORPG alliance chat

Here is how it looks ingame:
MMORPG alliance chat example message

Scripting Documentation

The noobchat Script should always be attached to the ChatPanel. The Script offers a few functions that can be used by other JavaScript, C# or Boo Scripts:

// chan_add adds a channel to the channels array.
// it will also join the channel if chan_add is
// called while being connected to the server
public void chan_add(string channel,
                     string password,
                     string command,
                     string identifierOut,
                     string identifierIn,
                     Color color)

 
// chan_remove removes a channel from the channels array.
// it will also leave the channel if chan_remove is
// called while being connected to the server                    
public void chan_remove(string channel)

Download

The download can be found at Unity Asset Store - noobchat
Note: in order to respect Unity's Asset Store agreement, noobchat is not part of the noobtuts Premium files right now.