Add Server and client
This commit is contained in:
parent
3d7c9e3f7f
commit
6258438d44
262 changed files with 2661 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
class Disconnect_Client_Packet : IPacket
|
||||
{
|
||||
public string pseudo;
|
||||
|
||||
public Disconnect_Client_Packet() { }
|
||||
|
||||
public Disconnect_Client_Packet(string pseudo) { this.pseudo = pseudo; }
|
||||
|
||||
void IPacket.read(DataBuffer data)
|
||||
{
|
||||
this.pseudo = data.getString();
|
||||
}
|
||||
|
||||
void IPacket.write(DataBuffer data)
|
||||
{
|
||||
data.put(Register.getId(typeof(Disconnect_Client_Packet)));
|
||||
data.put(this.pseudo);
|
||||
}
|
||||
|
||||
void IPacket.manage(byte[] data, Client client)
|
||||
{
|
||||
if (pseudo.Equals(MainClient.pseudo))
|
||||
{
|
||||
MainClient.connected = MainState_Connection_Request_Packet.DISCONNECTED;
|
||||
MainClient.client.disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09c2a6099528c8445b15ffe7adbde542
|
||||
timeCreated: 1461172729
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
class MainState_Connection_Request_Packet : IPacket
|
||||
{
|
||||
|
||||
public static readonly int REQUEST = 0, ACCEPTED = 1, REFUSED = 2, TIME_OUT = 3, ALREADY_CONNECTED = 4, PSEUDO_INCORRECT = 5,DISCONNECTED = 6;
|
||||
|
||||
public String pseudo;
|
||||
public int id;
|
||||
|
||||
public MainState_Connection_Request_Packet() { }
|
||||
|
||||
public MainState_Connection_Request_Packet(String pseudo,int id)
|
||||
{
|
||||
this.pseudo = pseudo;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
void IPacket.write(DataBuffer data)
|
||||
{
|
||||
data.put(Register.getId(typeof(MainState_Connection_Request_Packet)));
|
||||
data.put(pseudo);
|
||||
data.put(id);
|
||||
}
|
||||
|
||||
void IPacket.read(DataBuffer data)
|
||||
{
|
||||
this.pseudo = data.getString();
|
||||
this.id = data.getInt();
|
||||
}
|
||||
|
||||
void IPacket.manage(byte[] data, Client client)
|
||||
{
|
||||
if(id == ACCEPTED)
|
||||
{
|
||||
MainClient.connected = ACCEPTED;
|
||||
MainClient.pseudo = this.pseudo;
|
||||
}
|
||||
else if(id == REFUSED)
|
||||
{
|
||||
MainClient.connected = REFUSED;
|
||||
}
|
||||
else if (id == ALREADY_CONNECTED)
|
||||
{
|
||||
MainClient.connected = ALREADY_CONNECTED;
|
||||
}
|
||||
else if (id == PSEUDO_INCORRECT)
|
||||
{
|
||||
MainClient.connected = PSEUDO_INCORRECT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e632acbe3e907fb42992ec51c2549272
|
||||
timeCreated: 1461155199
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
class MessagePacket : IPacket
|
||||
{
|
||||
|
||||
private String pseudo, message;
|
||||
|
||||
public MessagePacket() { }
|
||||
|
||||
public MessagePacket(String pseudo, String message)
|
||||
{
|
||||
this.message = message;
|
||||
this.pseudo = pseudo;
|
||||
}
|
||||
|
||||
void IPacket.read(DataBuffer data)
|
||||
{
|
||||
this.pseudo = data.getString();
|
||||
this.message = data.getString();
|
||||
}
|
||||
|
||||
void IPacket.write(DataBuffer data)
|
||||
{
|
||||
data.put(Register.getId(typeof(MessagePacket)));
|
||||
data.put(this.pseudo);
|
||||
data.put(this.message);
|
||||
}
|
||||
|
||||
void IPacket.manage(byte[] data,Client client)
|
||||
{
|
||||
Debug.Log(this.pseudo + " : " + this.message);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6df0f62eafd1c224ea52a0721bc3e4b1
|
||||
timeCreated: 1461092835
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,27 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PingPacket : IPacket {
|
||||
|
||||
public long current;
|
||||
|
||||
public PingPacket()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IPacket.read(DataBuffer data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IPacket.write(DataBuffer data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IPacket.manage(byte[] data, Client client)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c3875a60f90ff146950d2ad190f0e09
|
||||
timeCreated: 1462518396
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue