public void addUserAndSave(User user) { if (this.commNodeUsers.ContainsKey(user.id)) { return; } var nodeSave = new List <CommNodeUser>(); //add User to CommNode var newUser = new CommNodeUser(user.id, this.id); this.commNodeUsers.TryAdd(user.id, newUser); user.commNodeRights.Add(this.id, newUser); nodeSave.Add(newUser); Core.Instance.dataConnection.saveCommNodeUsers(nodeSave); }
private bool addToNode(User user) { List <Lockable> elementsToLock = new List <Lockable>(1); elementsToLock.Add(this); if (!LockingManager.lockAllOrSleep(elementsToLock)) { return(false); } try { //add contact data from this commNode to users contacts: /* * foreach (var commNodeUser in this.commNodeUsers) * { * User commUser = Core.Instance.users[commNodeUser.Key]; * if (Core.Instance.userRelations.hasContact(user, commUser)) continue; * * Core.Instance.userRelations.addUserRelation(user, commUser, newContacts); * } * * * //save new contact data: * Core.Instance.dataConnection.saveDiplomaticEntities(newContacts); */ //add User to CommNode var newUser = new CommNodeUser(user.id, this.id); this.commNodeUsers.TryAdd(user.id, newUser); user.commNodeRights.Add(this.id, newUser); //and save to DB: var toSave = new List <CommNodeUser>(); toSave.Add(newUser); Core.Instance.dataConnection.saveCommNodeUsers(toSave); } finally { LockingManager.unlockAll(elementsToLock); } return(true); }
public static void createCommNodeBuilding(ColonyBuilding building) { if (building.buildingId != 8) { return; } CommunicationNode node = new CommunicationNode((int)Core.Instance.identities.commNode.getNext()); node.userId = building.userId; node.name = building.colony.name; node.unformattedName = building.colony.name; node.positionX = building.colony.X; node.positionY = building.colony.Y; node.systemX = building.colony.SystemX; node.systemY = building.colony.SystemY; node.connectionType = 1; node.connectionId = building.id; node.activ = true; var instance = Core.Instance; instance.commNodes.TryAdd(node.id, node); //add to tree SpacegameServer.Core.NodeQuadTree.Field commNodeField2 = new SpacegameServer.Core.NodeQuadTree.Field(node.positionX, node.positionY); instance.nodeQuadTree.insertNode(commNodeField2, node.id); //add CommNodeUser CommNodeUser user = new CommNodeUser(building.userId, node.id); node.commNodeUsers.TryAdd(building.userId, user); instance.users[building.userId].commNodeRights.Add(node.id, user); instance.dataConnection.saveCommNode(node); building.node = node; }
public static void CreateAllianceNode(Alliance alliance) { CommunicationNode node = new CommunicationNode((int)Core.Instance.identities.commNode.getNext()); node.userId = alliance.allianceowner; node.name = alliance.NAME; node.unformattedName = alliance.NAME; node.connectionType = 4; node.connectionId = alliance.id; node.activ = true; var instance = Core.Instance; instance.commNodes.TryAdd(node.id, node); //add CommNodeUser CommNodeUser user = new CommNodeUser((int)alliance.allianceowner, node.id); node.commNodeUsers.TryAdd((int)alliance.allianceowner, user); instance.users[(int)alliance.allianceowner].commNodeRights.Add(node.id, user); instance.dataConnection.saveCommNode(node); }