/// <summary> /// Buffer: /// int PacketNum; /// string race; /// int spellCount; /// short[spellCount] spellIndex /// </summary> private static void HandleSaveSkillBuild(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); string race = buffer.ReadString(); int spellCount = buffer.ReadInteger(); string[] spellBuild = new string[spellCount]; for (int i = 0; i < spellCount; i++) { string spellIndex = "" + buffer.ReadShort(); while (spellIndex.Length != 4) { spellIndex = "0" + spellIndex; } string spellType = "" + buffer.ReadShort(); while (spellType.Length != 4) { spellType = "0" + spellType; } spellBuild[i] = spellIndex + "" + spellType; } buffer.Dispose(); //Global.data.SetSkillBuildData(client.nickname, race, spellBuild); SendDataTCP.SendBuildSaved(client); }
/// <summary> /// Buffer: /// int PacketNum; /// </summary> private static void HandleQueueStop(ClientTCP client, byte[] data) { Queue.StopSearch(client); foreach (ClientTCP friend in client.friends) { SendDataTCP.SendFriendChange(client, friend); } }
/// <summary> /// Buffer: /// int PacketNum; /// string message; /// </summary> private static void HandleGlChatMsg(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); SendDataTCP.SendGlChatMsg(client.nickname, buffer.ReadString() /* message */); buffer.Dispose(); }
public void LoadSpells(ClientTCP client) { short[][] spellBuilds = new short[PlayersCount][]; for (int i = 0; i < PlayersCount; i++) { spellBuilds[i] = playersTCP[i].accountData.AccountSkillBuilds.IgnisBuild.ToArray(); } SendDataTCP.SendLoadSpells(client, spellBuilds); }
private void StartLoad() { Status = RoomState.Loading; foreach (ClientTCP player in playersTCP) { player.clientState = ClientTCPState.GameRoom; player.playerState = NetPlayerState.Playing; } SendDataTCP.SendMatchFound(this); }
public void Surrended(ClientTCP client) { CloseUpdateTimer(); Status = RoomState.MatchEnded; foreach (ClientTCP player in playersTCP) { player.playerState = NetPlayerState.EndPlaying; } _closeTimer = new Timer(EndGameSession, null, 300000, Timeout.Infinite); SendDataTCP.SendMatchEnded(client.nickname, this); }
private static void AcceptCallback(IAsyncResult ar) { if (!Closed) { Socket socket = _serverSocket.EndAccept(ar); _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null); ClientTCP client = new ClientTCP(socket, socket.RemoteEndPoint as IPEndPoint); Global.clientList.Add(client); SendDataTCP.SendClientConnetionOK(client); } }
/// <summary> /// Buffer: /// int PacketNum; /// string race; /// </summary> private static void HandleGetSkillBuild(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); string race = buffer.ReadString(); buffer.Dispose(); short[] skillBuild = client.accountData.AccountSkillBuilds.IgnisBuild.ToArray(); SendDataTCP.SendSkillBuild(client, skillBuild, race); }
public void SpawnTree(ClientTCP client, int treeCount, bool bigTree, bool mediumTree, bool smallTree) { int[] ranges; lock (expectant) { if (!staticObjectsList.GetRange(StaticTypes.tree, out ranges)) { ranges = staticObjectsList.Add(StaticTypes.tree, ObjectType.staticObjects, this, treeCount, bigTree, mediumTree, smallTree); } } SendDataTCP.SendTreeSpawned(client, ranges); }
public void SpawnRock(ClientTCP client, int rockCount, bool bigRock, bool mediumRock, bool smallRock) { int[] ranges; lock (expectant) { if (!staticObjectsList.GetRange(StaticTypes.rock, out ranges)) { ranges = staticObjectsList.Add(StaticTypes.rock, ObjectType.staticObjects, this, rockCount, bigRock, mediumRock, smallRock); } } SendDataTCP.SendRockSpawned(client, ranges); }
private void EndGameSession(Object o) { _closeTimer.Dispose(); for (int i = 0; i < PlayersCount; i++) { if (playersTCP[i] != null) { SendDataTCP.SendRoomLogOut(playersTCP[i]); DeletePlayer(playersTCP[i]); } } }
/// <summary> /// Buffer: /// int PacketNum; /// int matchType; /// string race; /// </summary> private static void HandleQueueStart(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); Queue.StartSearch(client, buffer.ReadInteger(), buffer.ReadString()); foreach (ClientTCP friend in client.friends) { SendDataTCP.SendFriendChange(client, friend); } buffer.Dispose(); }
private void txtChat_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue.Equals(13)) { if (!ServerTCP.Closed) { if (!String.IsNullOrEmpty(txtChat.Text)) { if (txtChat.Text.StartsWith("/")) { string[] commands = txtChat.Text.Split(' '); switch (commands[0]) { case "/AddAccount": if (commands.Length == 4) { Global.data.AddAccount(commands[1], commands[2], commands[3]); } else { Global.serverForm.Debug("Invalid arguments in command: " + commands[0]); } break; case "/AddMap": if (commands.Length == 16) { Global.data.AddMap(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3]), new float[] { float.Parse(commands[4]), float.Parse(commands[5]) }, new float[] { float.Parse(commands[6]), float.Parse(commands[7]) }, new float[] { float.Parse(commands[8]), float.Parse(commands[9]), float.Parse(commands[10]), float.Parse(commands[11]) }, new float[] { float.Parse(commands[12]), float.Parse(commands[13]), float.Parse(commands[14]), float.Parse(commands[15]) }); } else { Global.serverForm.Debug("Invalid arguments in command: " + commands[0]); } break; default: Global.serverForm.Debug("Unknown command"); break; } } else { SendDataTCP.SendGlChatMsg("Server", txtChat.Text); txtChat.Text = ""; } } } } }
/// <summary> /// Buffer: /// int PacketNum; /// int sceneIndex; /// </summary> public static void SendMatchFound(BaseGameRoom room) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteInteger((int)ServerPackets.SMatchFound); buffer.WriteInteger((int)room.roomType); foreach (ClientTCP player in room.playersTCP) { foreach (ClientTCP friend in player.friends) { SendDataTCP.SendFriendChange(player, friend); } } ServerTCP.SendDataToRoomPlayers(room, buffer.ToArray()); buffer.Dispose(); }
public void Add(BaseGameRoom room, int spellIndex, int parentIndex, float[] spawnPos, float[] targetPos, float[] rot, int hp, string nickname) { int caster = -1; for (int i = 0; i < room.PlayersCount; i++) { if (room.playersTCP[i].nickname.Equals(nickname)) { caster = i; break; } } int index = Add(room, hp, spawnPos, rot, caster); SendDataTCP.SendInstantiate(room, spellIndex, index, parentIndex, spawnPos, targetPos, rot, hp, nickname); }
public void AddFriend(string GuideKey) { foreach (ClientTCP player in Global.clientList) { if (player.accountData.GuideKey.Equals(GuideKey)) { List <string> Friends = accountData.Friends.ToList(); if (!Friends.Contains(GuideKey)) { Friends.Add(GuideKey); accountData.Friends = Friends.AsEnumerable(); Global.data.SaveAccount(accountData); SendDataTCP.SendFriendInfo(this, player); break; } break; } } }
/// <summary> /// Buffer: /// int PacketNum; /// string username; /// string password; /// </summary> private static void HandleLoginTry(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); string username = buffer.ReadString(); if (!Global.data.LoginExist(username)) { SendDataTCP.SendClientAlert(client, "Username does not exist."); return; } if (!Global.data.PasswordIsOkay(username, buffer.ReadString())) { SendDataTCP.SendClientAlert(client, "Invalid password."); return; } client.LogIn(username); buffer.Dispose(); }
public void LogIn(string username) { accountData = Global.data.GetAccount(username); nickname = accountData.Nickname; playerState = NetPlayerState.InMainLobby; clientState = ClientTCPState.MainLobby; foreach (string guideKey in accountData.Friends.ToArray()) { foreach (ClientTCP friend in Global.clientList) { if (friend.accountData.GuideKey.Equals(guideKey)) { friends.Add(friend); friend.friends.Add(this); SendDataTCP.SendFriendInfo(friend, this); break; } } } SendDataTCP.SendLoginOk(nickname, this); }
public void LoadComplite(ClientTCP client) { lock (expectant) { _loadedTCP[client.ID] = true; foreach (bool loaded in _loadedTCP) { if (!loaded) { return; } } foreach (bool loaded in _loadedUDP) { if (!loaded) { return; } } Status = RoomState.Playing; SendDataTCP.SendRoomStart(this); StartUpdate(); } }
/// <summary> /// Buffer: /// int PacketNum; /// string username; /// string password; /// string nickname; /// </summary> private static void HandleRegisterTry(ClientTCP client, byte[] data) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(data); buffer.ReadInteger(); string username = buffer.ReadString(); string password = buffer.ReadString(); string nickname = buffer.ReadString(); if (Global.data.LoginExist(username)) { SendDataTCP.SendClientAlert(client, "Username already exist"); return; } if (Global.data.NicknameExist(nickname)) { SendDataTCP.SendClientAlert(client, "Nickname already exist"); return; } Global.data.AddAccount(username, password, nickname); buffer.Dispose(); SendDataTCP.SendRegisterOk(client); }
public void Close() { if (clientState != ClientTCPState.Sleep) { if (clientState == ClientTCPState.Entrance) { clientState = ClientTCPState.Sleep; try { socket.Dispose(); } catch (Exception ex) { Global.serverForm.Debug(ex + ""); } foreach (ClientTCP friend in friends) { SendDataTCP.SendFriendLeave(this, friend); friend.friends.Remove(this); } Global.clientList.Remove(this); } else if (clientState == ClientTCPState.MainLobby) { clientState = ClientTCPState.Sleep; try { socket.Dispose(); } catch (Exception ex) { Global.serverForm.Debug(ex + ""); } foreach (ClientTCP friend in friends) { SendDataTCP.SendFriendLeave(this, friend); friend.friends.Remove(this); } Global.clientList.Remove(this); SendDataTCP.SendGlChatMsg("Server", $"Player { nickname } disconnected."); } else if (clientState == ClientTCPState.GameRoom) { clientState = ClientTCPState.Sleep; if (playerState == NetPlayerState.SearchingForMatch) { room.DeletePlayer(this); } else if (playerState == NetPlayerState.Playing) { room.AbortGameSession(this); } else if (playerState == NetPlayerState.EndPlaying) { room.DeletePlayer(this); } foreach (ClientTCP friend in friends) { SendDataTCP.SendFriendLeave(this, friend); friend.friends.Remove(this); } Global.serverForm.Debug($"GamePlayer {nickname} lost connection"); Global.clientList.Remove(this); } Global.serverForm.RemoveClient(this); } }
public void SetPlayers(ClientTCP client) { SendDataTCP.SendPlayersSpawned(client, this); }
private static void HandleRoomLeave(ClientTCP client, byte[] data) { SendDataTCP.SendRoomLogOut(client); client.room.DeletePlayer(client); }
public void SetLoadProgress(ClientTCP client, float loadProgress) { SendDataTCP.SendEnemyProgress(this, client, client.load = loadProgress); }
public void SetGameArea(ClientTCP client) { SendDataTCP.SendMapData(_mapIndex, client); }
/// <summary> /// Buffer: /// int PacketNum; /// </summary> private static void HandlePlayerConnect(ClientTCP client, byte[] data) { SendDataTCP.SendPlayerConnectionOK(client); SendDataTCP.SendFriendsInfo(client); }
public override void TakeDamage(ClientTCP client, int index, int PhysicDamage, int IgnisDamage, int TerraDamage, int AquaDamage, int CaeliDamage, int PureDamage, bool Heal) { SendDataTCP.SendDamage(client, index, type, index, PhysicDamage, IgnisDamage, TerraDamage, CaeliDamage, AquaDamage, PureDamage, Heal); }
public override void Destroy(BaseGameRoom room) { SendDataTCP.SendDestroy(room, index, type); room.dynamicObjectsList.Destroy(index); }