Functional networkevent validation, functional single player saving, requireditem ui texts, titlescreen & loading
This commit is contained in:
@@ -93,6 +93,8 @@ namespace Subsurface.Networking
|
||||
//update.Elapsed += new System.Timers.ElapsedEventHandler(Update);
|
||||
|
||||
// Funtion that waits for connection approval info from server
|
||||
|
||||
reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to " + serverIP, new string[0]);
|
||||
CoroutineManager.StartCoroutine(WaitForStartingInfo());
|
||||
|
||||
// Start the timer
|
||||
@@ -106,11 +108,17 @@ namespace Subsurface.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SelectMainMenu(GUIButton button, object obj)
|
||||
{
|
||||
Disconnect();
|
||||
Game1.NetworkMember = null;
|
||||
Game1.MainMenuScreen.Select();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Before main looping starts, we loop here and wait for approval message
|
||||
private IEnumerable<Status> WaitForStartingInfo()
|
||||
{
|
||||
reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to "+serverIP, new string[0]);
|
||||
|
||||
// When this is set to true, we are approved and ready to go
|
||||
bool CanStart = false;
|
||||
|
||||
@@ -162,7 +170,14 @@ namespace Subsurface.Networking
|
||||
}
|
||||
break;
|
||||
case NetIncomingMessageType.StatusChanged:
|
||||
Debug.WriteLine((NetConnectionStatus)inc.ReadByte());
|
||||
NetConnectionStatus connectionStatus = (NetConnectionStatus)inc.ReadByte();
|
||||
Debug.WriteLine(connectionStatus);
|
||||
|
||||
if (connectionStatus != NetConnectionStatus.Connected)
|
||||
{
|
||||
string denyMessage = inc.ReadString();
|
||||
DebugConsole.ThrowError(denyMessage);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -179,13 +194,15 @@ namespace Subsurface.Networking
|
||||
|
||||
if (Client.ConnectionStatus != NetConnectionStatus.Connected)
|
||||
{
|
||||
reconnectBox = new GUIMessageBox("CONNECTION FAILED", "Failed to connect to server.", new string[] { "Retry", "Cancel" });
|
||||
reconnectBox.Buttons[0].OnClicked += RetryConnection;
|
||||
reconnectBox.Buttons[0].OnClicked += reconnectBox.Close;
|
||||
var reconnect = new GUIMessageBox("CONNECTION FAILED", "Failed to connect to server.", new string[] { "Retry", "Cancel" });
|
||||
reconnect.Buttons[0].OnClicked += RetryConnection;
|
||||
reconnect.Buttons[0].OnClicked += reconnect.Close;
|
||||
reconnect.Buttons[1].OnClicked += SelectMainMenu;
|
||||
reconnect.Buttons[1].OnClicked += reconnect.Close;
|
||||
}
|
||||
else
|
||||
{
|
||||
Game1.NetLobbyScreen.Select();
|
||||
if (Screen.Selected == Game1.MainMenuScreen) Game1.NetLobbyScreen.Select();
|
||||
connected = true;
|
||||
}
|
||||
|
||||
@@ -195,21 +212,32 @@ namespace Subsurface.Networking
|
||||
public override void Update()
|
||||
{
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.K))
|
||||
{
|
||||
SendRandomData();
|
||||
}
|
||||
//if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.K))
|
||||
//{
|
||||
// SendRandomData();
|
||||
//}
|
||||
//if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.L))
|
||||
//{
|
||||
// ConnectToServer(serverIP);
|
||||
//}
|
||||
|
||||
|
||||
if (gameStarted) inGameHUD.Update((float)Physics.step);
|
||||
|
||||
if (!connected || updateTimer > DateTime.Now) return;
|
||||
|
||||
if (Client.ConnectionStatus == NetConnectionStatus.Disconnected)
|
||||
if (Client.ConnectionStatus == NetConnectionStatus.Disconnected && reconnectBox==null)
|
||||
{
|
||||
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
|
||||
|
||||
connected = false;
|
||||
ConnectToServer(serverIP);
|
||||
return;
|
||||
}
|
||||
else if (reconnectBox!=null)
|
||||
{
|
||||
reconnectBox.Close(null,null);
|
||||
reconnectBox = null;
|
||||
}
|
||||
|
||||
if (myCharacter != null)
|
||||
{
|
||||
@@ -368,8 +396,8 @@ namespace Subsurface.Networking
|
||||
Game1.NetLobbyScreen.Select();
|
||||
|
||||
if (Game1.GameSession!=null) Game1.GameSession.EndShift("");
|
||||
|
||||
DebugConsole.ThrowError(endMessage);
|
||||
|
||||
new GUIMessageBox("The round has ended", endMessage);
|
||||
|
||||
myCharacter = null;
|
||||
|
||||
|
||||
@@ -120,24 +120,52 @@ namespace Subsurface.Networking
|
||||
|
||||
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
||||
|
||||
|
||||
Client existingClient = connectedClients.Find(c=> c.Connection == inc.SenderConnection);
|
||||
if (existingClient==null)
|
||||
{
|
||||
string version = "", name = "";
|
||||
try
|
||||
{
|
||||
version = inc.ReadString();
|
||||
name = inc.ReadString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
inc.SenderConnection.Deny("Connection error - server failed to read your ConnectionApproval message");
|
||||
break;
|
||||
}
|
||||
|
||||
if (version != Game1.Version.ToString())
|
||||
{
|
||||
inc.SenderConnection.Deny("Subsurface version " + Game1.Version + " required to connect to the server (Your version: " + version + ")");
|
||||
break;
|
||||
}
|
||||
else if (connectedClients.Find(c => c.name.ToLower() == name.ToLower())!=null)
|
||||
{
|
||||
inc.SenderConnection.Deny("The name ''" + name + "'' is already in use. Please choose another name.");
|
||||
break;
|
||||
}
|
||||
|
||||
int id = 1;
|
||||
while (connectedClients.Find(c=>c.ID==id)!=null)
|
||||
{
|
||||
id++;
|
||||
}
|
||||
Client newClient = new Client(name, id);
|
||||
newClient.Connection = inc.SenderConnection;
|
||||
newClient.version = version;
|
||||
|
||||
connectedClients.Add(newClient);
|
||||
|
||||
inc.SenderConnection.Approve();
|
||||
}
|
||||
else
|
||||
{
|
||||
inc.SenderConnection.Deny();
|
||||
}
|
||||
//Character ch = new Character("Content/Characters/Human/human.xml");
|
||||
|
||||
string version = inc.ReadString();
|
||||
string name = inc.ReadString();
|
||||
|
||||
int id = 1;
|
||||
while (connectedClients.Find(c=>c.ID==id)!=null)
|
||||
{
|
||||
id++;
|
||||
}
|
||||
|
||||
Client newClient = new Client(name, id);
|
||||
newClient.Connection = inc.SenderConnection;
|
||||
newClient.version = version;
|
||||
|
||||
connectedClients.Add(newClient);
|
||||
|
||||
inc.SenderConnection.Approve();
|
||||
break;
|
||||
case NetIncomingMessageType.StatusChanged:
|
||||
Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status);
|
||||
@@ -151,7 +179,11 @@ namespace Subsurface.Networking
|
||||
{
|
||||
DisconnectClient(sender, sender.name+" was unable to connect to the server (nonmatching game version)",
|
||||
"Subsurface version " + Game1.Version + " required to connect to the server (Your version: " + sender.version + ")");
|
||||
|
||||
}
|
||||
else if (connectedClients.Find(x => x.name == sender.name && x != sender)!=null)
|
||||
{
|
||||
DisconnectClient(sender, sender.name + " was unable to connect to the server (name already in use)",
|
||||
"The name ''"+sender.name+"'' is already in use. Please choose another name.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -178,8 +210,7 @@ namespace Subsurface.Networking
|
||||
if (myClient != null) outmsg.Write(myClient.name);
|
||||
|
||||
Server.SendMessage(outmsg, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
|
||||
|
||||
|
||||
//notify other clients about the new client
|
||||
outmsg = Server.CreateMessage();
|
||||
outmsg.Write((byte)PacketTypes.PlayerJoined);
|
||||
@@ -200,8 +231,6 @@ namespace Subsurface.Networking
|
||||
DisconnectClient(inc.SenderConnection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case NetIncomingMessageType.Data:
|
||||
|
||||
@@ -380,7 +409,7 @@ namespace Subsurface.Networking
|
||||
|
||||
private bool EndButtonHit(GUIButton button, object obj)
|
||||
{
|
||||
Game1.GameSession.gameMode.End("The round has ended");
|
||||
Game1.GameSession.gameMode.End("Server admin has ended the round");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -454,14 +483,15 @@ namespace Subsurface.Networking
|
||||
public void KickPlayer(string playerName)
|
||||
{
|
||||
playerName = playerName.ToLower();
|
||||
Client client = null;
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.name.ToLower() != playerName) continue;
|
||||
client = c;
|
||||
if (c.name.ToLower() == playerName) KickClient(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void KickClient(Client client)
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
DisconnectClient(client, client.name + " has been kicked from the server", "You have been kicked from the server");
|
||||
@@ -526,9 +556,22 @@ namespace Subsurface.Networking
|
||||
|
||||
private void ReadCharacterData(NetIncomingMessage message)
|
||||
{
|
||||
string name = message.ReadString();
|
||||
Gender gender = message.ReadBoolean() ? Gender.Male : Gender.Female;
|
||||
int headSpriteId = message.ReadInt32();
|
||||
string name = "";
|
||||
Gender gender = Gender.Male;
|
||||
int headSpriteId = 0;
|
||||
|
||||
try
|
||||
{
|
||||
name = message.ReadString();
|
||||
gender = message.ReadBoolean() ? Gender.Male : Gender.Female;
|
||||
headSpriteId = message.ReadInt32();
|
||||
}
|
||||
catch
|
||||
{
|
||||
name = "";
|
||||
gender = Gender.Male;
|
||||
headSpriteId = 0;
|
||||
}
|
||||
|
||||
|
||||
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace Subsurface.Networking
|
||||
public NetworkMember()
|
||||
{
|
||||
inGameHUD = new GUIFrame(new Rectangle(0,0,0,0), null, null);
|
||||
inGameHUD.CanBeFocused = false;
|
||||
|
||||
int width = 350, height = 100;
|
||||
chatBox = new GUIListBox(new Rectangle(
|
||||
@@ -70,6 +71,7 @@ namespace Subsurface.Networking
|
||||
var textBox = new GUITextBox(
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.TopLeft, Alignment.Left, GUI.style, inGameHUD);
|
||||
textBox.Font = GUI.SmallFont;
|
||||
textBox.OnEnter = EnterChatMessage;
|
||||
}
|
||||
|
||||
@@ -89,22 +91,27 @@ namespace Subsurface.Networking
|
||||
{
|
||||
Game1.NetLobbyScreen.NewChatMessage(message, messageColor[(int)messageType]);
|
||||
|
||||
while (chatBox.CountChildren > 20)
|
||||
{
|
||||
chatBox.RemoveChild(chatBox.children[1]);
|
||||
}
|
||||
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), message,
|
||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, messageColor[(int)messageType],
|
||||
Alignment.Left, null, null, true);
|
||||
msg.Font = GUI.SmallFont;
|
||||
|
||||
msg.Padding = new Vector4(20.0f, 0, 0, 0);
|
||||
|
||||
//float prevScroll = chatBox.BarScroll;
|
||||
|
||||
//chatBox.AddChild(msg);
|
||||
float prevSize = chatBox.BarSize;
|
||||
float oldScroll = chatBox.BarScroll;
|
||||
|
||||
//while (chatBox.CountChildren > 20)
|
||||
//{
|
||||
// chatBox.RemoveChild(chatBox.children[0]);
|
||||
//}
|
||||
msg.Padding = new Vector4(20, 0, 0, 0);
|
||||
chatBox.AddChild(msg);
|
||||
|
||||
//if (prevScroll == 1.0f) chatBox.BarScroll = 1.0f;
|
||||
if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f;
|
||||
|
||||
GUI.PlayMessageSound();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user