]>
jfr.im git - irc/rizon/acid.git/blob - vizon/src/main/java/net/rizon/acid/plugins/vizon/VhostManager.java
5c3a8bbfcd8ea487eba0cbc230ea48d0b4ef7a4e
2 * Copyright (c) 2017, orillion <orillion@rizon.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
26 package net
.rizon
.acid
.plugins
.vizon
;
28 import net
.rizon
.acid
.plugins
.vizon
.db
.VizonRequest
;
29 import net
.rizon
.acid
.plugins
.vizon
.db
.VizonUser
;
30 import java
.util
.regex
.Pattern
;
31 import net
.rizon
.acid
.core
.Acidictive
;
32 import net
.rizon
.acid
.core
.Protocol
;
33 import net
.rizon
.acid
.core
.User
;
34 import org
.slf4j
.Logger
;
35 import org
.slf4j
.LoggerFactory
;
39 * @author orillion <orillion@rizon.net>
41 public class VhostManager
43 private static final Logger logger
= LoggerFactory
.getLogger(VhostManager
.class);
44 private static final String DELETE_FORMAT
= "DEL %s";
46 public static final Pattern NORMAL_PATTERN
= Pattern
.compile("^[\u0003\u000Fa-zA-Z0-9-.]*[a-zA-Z]+[\u0003\u000Fa-zA-Z0-9-.]*$");
47 public static final Pattern BOLD_PATTERN
= Pattern
.compile("^[\u0003\u0002\u000Fa-zA-Z0-9-.]*[a-zA-Z]+[\u0003\u0002\u000Fa-zA-Z0-9-.]*$");
54 public boolean assignVhost(VizonRequest request
)
56 VizonUser user
= Vizon
.getVizonDatabase().findUserById(request
.getUserId());
63 Acidictive
.privmsg("HostServ", String
.format(DELETE_FORMAT
, user
.getNick()));
65 user
.setVhost(request
.getVhost());
66 user
.setEligible(false);
68 if (!Vizon
.getVizonDatabase().updateUser(user
))
73 User u
= User
.findUser(request
.getNick());
77 this.applyVhostIfApplicable(u
);
83 public void applyVhostIfApplicable(User user
)
85 if (user
== null || !user
.isIdentified())
90 VizonUser u
= Vizon
.getVizonDatabase().findUser(user
.getNick());
97 Protocol
.chghost(user
, u
.getVhost());
98 u
.setVhost(u
.getVhost());
101 public void expireVhosts()
103 int expired
= Vizon
.getVizonDatabase().expireVhosts();
105 // Users can keep their colored vhosts until they log out, when they expire.
106 logger
.info("Expired {} vhosts", expired
);