[LIDGREN TUTORIAL]

I have been working on getting Unity working with the Lidgren networking library.

So far I have a simple Chat client where you can connect either with a web player or windows / Mac client to the server and send messages back and forth.

I will be creating a full blown tutorial with a demo level as well as releasing the server + source for the server.

Demo Will include:

Connecting to server
Logging in to server
Sending / Receiving Chat Messages
Sending / Receiving Transform
Sending / Receiving Functions
Instancing of Other Player prefabs
3RD person and First Person camera modes
Multiple Spawn Points

Planned features also will be zones, db access from the server etc for player stats, position, etc.

This Demo won’t be any GameType specific just a networking demo.

I’m wondering if $25 is a good price for this Demo.

Here is an example of the ChatClient without the gui etc.

This is just my debug version and not the finished tutorial code that is using some code from the lidgren samples etc.

using UnityEngine;
using System.Collections;
using Lidgren.Network;
using System.Threading;

public class ChatMessage
	{
		public string Sender;
		public string Text;
	}
	
public class ClientApp : MonoBehaviour {
	
	public NetClient client;
	public NetPeerConfiguration config;
	
	private static bool s_keepGoing = true;

	// Use this for initialization
	void Start () {
		
		
	// create a client with a default configuration
	config = new NetPeerConfiguration("Chat");
	client = new NetClient(config);
    client.Start();
	client.Connect("localhost", 14242);
	
			// Wait half a second to allow server to start up if run via Visual Studio
			Thread.Sleep(500);
			// Send chat message
			//SendMessages("test")
	}
	
	
	
	// Update is called once per frame
	void Update () {
		// create a buffer to read data into
	NetIncomingMessage inc;
	
	RBSChatController rbsCC = GetComponent<RBSChatController>();		
		
	
			// check if any messages has been received
				while ((inc = client.ReadMessage()) != null)
				{
					switch (inc.MessageType)
					{
						//case NetIncomingMessageType.ServerDiscovered:
						//case NetIncomingMessageType.ConnectionRejected:
							//Console.WriteLine("Rejected: " + buffer.ReadString());
							//break;
						case NetIncomingMessageType.DebugMessage:
						case NetIncomingMessageType.VerboseDebugMessage:
							//Console.WriteLine(buffer.ReadString());
							break;
						case NetIncomingMessageType.StatusChanged:
							string statusMessage = inc.ReadString();
							NetConnectionStatus newStatus = (NetConnectionStatus)inc.ReadByte();
							//rbsCC.AddChatMessage(newStatus.ToString());
							//Console.WriteLine("New status: " + newStatus + " (" + statusMessage + ")");
							break;
						case NetIncomingMessageType.Data:	
							// The server sent this data!
							
							ChatMessage cm = new ChatMessage();
							 inc.ReadAllFields(cm);
					
							//Console.WriteLine(msg);
							rbsCC.AddChatMessage("Received from " + cm.Sender + ": " + cm.Text);
							break;
					}
				}
				
		
			}
	
	
	public void SendMessages(string input){
		// Send chat message
		ChatMessage cm = new ChatMessage();
		cm.Sender = client.UniqueIdentifier.ToString();
		cm.Text = input;
		
		NetOutgoingMessage om = client.CreateMessage();
		om.WriteAllFields(cm);
		client.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 8);
	}
}

[/list]

hi !

25$ sounds fair but be sure to add all lidgren functionality like peer to peer or the ligren mmo stuff if you want to make money. If not I might not want to buy it.

But that’s my opinion.

What specific MMO and peer to peer stuff would you like to see…

The demo was going to be just like what you get with the Smartfox demo etc.

I don’t mind adding the other stuff but was thinking of making those modular so if someone wanted a peer to peer game instead of a mmo they could use the same demo etc.

I would say how to create a master server using lidgren and allow people to have peer to peer game.

http://code.google.com/p/lidgren-mmo/

I haven’t look at it but it sound some lidgren side project to create not mmo but 50 to 100 game party.

he second sound less interesting for my project but I4m sure a lot of people would like to use lidgren to create a 50-100 multiplayer game.

and it might be it. Also maybe when your tutorial is ready be sure to put it showcase because people didn’t really paid attention to it in this networking section.

$25 sounds fair if you include putting multiple characters on the same map and having them interact with one another.

Yea that’s the plan to have it where you can chat with each other and see the other players in the world.

hi there, i will buy if you can implement this:
1.make moving smooth(easy i think)
2.implement the network latency compensation for sync transform

I will make the movement smoothly and will implement latency compensation.

Anymore features for this that anyone can think of?

cool,i will be the first one to buy!!.

is that diffcult to implment client moving predication??

Yes the Network prediction is a bit difficult to implement.

Ok quick update:

I finally have the local player sending NetworkTransform only when it is different from the last known state.

Also with the server I’m adding the ability for:
Login
Validate User
GetUserList
AddUser
UpdateUser
DeleteUser

The user list will be the list of those in the game and it will include their current NetworkTransform so when the client receives the list it will check it’s current list and then spawn all remote players.

This network tutorial will be like the SmartFox tutorial but with more such as the login / verify user

What kind of login system would you like to see mysql db version? PHP login system, xml list?

Maybe I will include all three just to make it better.

Oh btw since I’m using lidgren there will already be 32 different message types.

I’m using a few of them for the LocalPlayer Transform sending, Remote Players Transform Sending, Server CMD’s.

With the Server CMD’s you can put the CMD type at the beginning of the message and use the correct SequenceChannel.

This way you can create any amount of server commands such as get players inventory, player info, validate user, etc.

This will only use 1 of the 32 sequence channels leaving many for you to use for whatever you want.

I’m also using one of the sequence channels for Chat, you could use one of the other sequence channels for other “Chat” channels etc such as combat, guild, zone, etc

Also with this tutorial you can speed or slow down the sending of movement so if you have a RPG type of game you can send movement every second, 10 milliseconds etc

But if you are doing a FPS type of game you can send movement updates every frame etc.

i prefer PHP login system

I will buy if the tutorial includes a pdf well detailed. :slight_smile:

It will include a pdf that is well documented and easy to follow.

PHP and mySQL will be done in the tutorial.

The PHP will be handled on the client side where the mySQL Authentication will be handled by the server.

$25? Great price.

I haven’t fallen off the face of the planet yet…just had a ton of personal things to take care of and a new job that I don’t have to work 80 + hours a week at.

Still working on this and will have something soon.

what does everyone think about the Kaleta.Network distribution library?

It’s built on top of Lidgren and has automatic object syncronization… I’ve played around with it a bit seems cool

Going to try to do player movement and remote player movement with it.

Will update with the results… if this works well then I will have my tutorial finished sooner than I thought.

Here’s a link for Kaleta http://kaleta.codeplex.com/wikipage?title=QuickStart&referringTitle=Home

Well the Kaleta Library doesn’t work well in Visual Studio 2010 for some reason.

So I went back to just using lidgren’s latest version from 11/13/2010

Made some progress on the handling of the player movement as well as other functions.

Why not use monodevelop?

True…I just like Visual Studio better than monodevelop.

Ok I finally have the player movement issues worked out… working on spawn points etc.

For the tutorial the server will have a Zone / Level spawn point editor or you can edit the Zones.xml file.

I’ll keep working in my spare time to get this to a working demo.